typedef with pointers
Code:
typedef struct information |
What is the error you are getting? It compiles fine for me...
Alex Brinister |
error is :: ‘reference_1’ does not name a type
|
Does your program look something like this?
Code:
#include <stdio.h> Is that your whole program? Is there more of it? Alex Brinister |
please , put the whole code as global than you will find that error !
|
Code:
typedef struct information The only error I get with this is a required '(' before the & symbol... Code:
test.c:10:1: error: expected identifier or '(' before '&' token |
You cannot have executable statements outside functions. Plus your names are really bad. Correction:
Code:
typedef struct Person |
That's why he has to put this code in a function...
Code:
int main() // or something Code:
typedef struct Person |
I got the same error after putting your statements as global. This is because, in global contexts you can initialise the global only once which is done along with the declaration itself.But you are using the 'global' (member_1 and reference_1) twice for initialising them.So, the error...If you don't initialise global during its declaration, they are by default initialised to NULL (in case of ptrs) or zero (in case of int/float/...). So, now to avoid the warnings and error you get, put the initialisation statement with the declrn of reference_1 as followed.
typedef struct information { char name[11]; int age; }info_1, *info_2; info_1 member_1; info_2 reference_1 = &member_1; /* reference_1 = &member_1; */ |
@ { Nevemteve & abrinister & SIG_SEGV } Sir , can you please tell me that
Code:
typedef struct Person person ; |
That is wrong syntax. If you are just typedefing a struct to a word, then you don't need the second person. In fact, you don't even need the first person. This would work.
Code:
typedef struct Code:
typdef struct Person Typedefing a struct is just like creating a struct. You cannot do this: Code:
struct Person; |
Pick one:
#1 Code:
typedef struct Person Person; Code:
struct Person Code:
typedef struct Person |
Code:
typedef struct Person Person; |
Because it doesn't follow C-syntax. (Perhaps you somehow confused typedef with #define. That's wrong.)
|
So, you have quite a confusion between definition and declaration of structure..... and working of typedef.
The place where you used typedef indicates that "Person" is a datatype of type 'struct Person' (here Person is a struct with no contents). That's it, here you declared "person" as typedefd datatype of (struct person)..... And again when you tried for declaring "person" as a structure containing (char[] and an int), compiler stuck here saying that it "expects identifier or ‘(’ before ‘{’ token". Because it is thinking that whatever that comes after the "Person" from now is every time a variable/identifier as the "Person" is previously typedefd as a datatype (like datatypes int , float, char, etc...)of (struct person). So your way of making things go wrong here....!!!Convinced????????????? |
All times are GMT -5. The time now is 02:19 AM. |