Sunday, 8 September 2013

C Pointer as arguement issue

C Pointer as arguement issue

I have a struct in a Header file : Header1.h
typedef struct
{ short SOMETHING; char* SOMETHING_ELSE;}SOME_STRUCT;
I have a function that requires a pointer to this struct in file : Code.c
void DO_SOMETHING(SOME_STRUCT *PVAL)
{ //Do something
}
I am declaring the function in another header : Header2.h
void DO_SOMETHING(SOME_STRUCT *);
In main.c I have the code:
int main(int argc, char **argv)
{
SOME_STRUCT STRUCTY, *ptrSOME_STRUCT;
ptrSOME_STRUCT = &STRUCTY;
DO_SOMETHING(ptrSOME_STRUCT);
return 0;
}
This in PellesC, CodeLite (GNU) and VC++2010 will not compile.
However if I change Header2.h to
void DO_SOMETHING(SOME_STRUCT);
VC++2010 will compile and run this, whereas CodeLite and PellesC do not.
I have enabled the option to Compile only C code in VS.
Also in all 3 IDEs if you have the function declaration at the top of my
Code.c file as
void DO_SOMETHING(SOME_STRUCT *);
it will compile.
As I am newish to C and pointers, how come this works under some compiles
and not others. Is this perhaps a bug? I am sorry in advance if this is
todo with some sytanical issue or a very basic question.

No comments:

Post a Comment