Reputation: 2519
Well, I have a header (my_prog.h) which looks like this:
#ifndef __MY_HEADER_H
#define __MY_HEADER_H
#include <stddef.h>
typedef struct {
size_t something;
size_t something_else;
}
void my_func();
#endif
and implementation file (my_prog.c) where I put:
#include "my_prog.h"
static size_t min(size_t a, size_t b) {...}
void my_func() {...}
When I try to compile my_prog.c to object file (I need it for linking with other files) I fet:
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘min’
The command I use for compiling is:
gcc -c my_prog.c -o my_prog.h
There's no error saying that it couldn't find the source. When I include in implementation file it compiles wihtout issues.
Upvotes: 0
Views: 169
Reputation: 454930
Remove the ...
from the function body. Having them is a syntax error.
You have not given a typedef name to the structure and the ;
is missing:
typedef struct {
size_t something;
size_t something_else;
} foo;
^^^^
In the compile line, following the -o
you are specifying the name of your header file. This is incorrect. If the compilation goes fine(it will if you fix 1 and 2 above) , the compiler the wipe the original contents of my_prog.h
and will overwrite it with the object file. Instead do :
gcc -c my_prog.c -o my_prog.o
Upvotes: 3