This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

accessing array of ptr in the structures

i've declared a structure as

typedef struct elem
{ int a;
void *b[20];
}e;

how can i access the array of (void) pointer inside a structure???

e.b ???

- is this correct manner of accessing???

Parents Reply Children
  • "The use of typedef together with structures almost always results in confusion for beginners."

    My observation has been that beginners tend to overuse typedef without questioning the merits of using typedefs versus explicit structs. This is only my opinion; in instances where the user doesn't really care about or access a structure's members (e.g. FILE in stdio.h) typedef'ing a struct has merit, but if a user's code accesses members using "." or "->" operators, I don't see the value in hiding an object's "structness" behind a typedef name. Again, that's just my opinion, but I might remember it also being the opinion of pundits on comp.lang.c.

  • I believe the reason most people prefer to typedef every struct, union and enum is the same that drives a good part of C's syntax: brevity. People want to be able to just write "foo" instead of "struct foo" every time they use one.