thanks! I have written a file with tests, "test_segment.c/h" and updated I have updated the Makefile. Every target " *.o" gets all its included headers as additional dependencies but my problem remains.
Is it correct to use a header file as requirement on multiple targets?
Or does the linker link methods multiple times and there is a name clash?
Thank you again for taking the time!
Code:
# Makefile
CFLAGS=-Wall
all: main test_segment
test_segment: test_segment.o debug.o segment.o
main: segment.o memory.o debug.o
# Implicit rules
test_segment.o: test_segment.c test_segment.h segment.h debug.h memory.h
segment.o: segment.c segment.h memory.h
memory.o: memory.c memory.h
debug.o: debug.c debug.h
Code:
//test_segment.h
#include "segment.h"
code_segment* build_test_segment();
void test_init_segment();
void test_append_segment();
void test_free_segment();
void fill_segment(uint8_t values[]);
void test_debug_file();
Code:
// test_segment.c
#include "test_segment.h"
#include "common.h"
#include "segment.h"
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include "debug.h"
implementation of the methods....
int main(int argc, char* argv[]){
main code.....
return 0;
}
and the "memory.c/h" file looks like this:
Code:
#ifndef memory_h
#define memory_h
#include "common.h"
#define GROW_CAPACITY(capacity) ((capacity) < 8 ? 8 : (capacity) * 2)
#define GROW_ARRAY(type, pointer, oldCount, newCount) \
(type*)reallocate(pointer, sizeof(type) * (oldCount), \
sizeof(type) * (newCount))
void* reallocate(void* pointer, size_t oldSize, size_t newSize);
#endif
Code:
#include <stdlib.h>
#include "memory.h"
void* reallocate(void* pointer, size_t oldSize, size_t newSize) {
if (newSize == 0) {
free(pointer);
return NULL;
}
void* result = realloc(pointer, newSize);
if (result == NULL){
exit(1);
}
return result;
}