referencing struct fields in c with square brackets and an index instead of . and ->?
- by lsiebert
Assuming I have a structure such as:
typedef struct
{
char * string1;
char * string2;
} TWO_WORDS;
such that all the fields are of the same type, and my main has
TWO_WORDS tw;
can I reference string1 with tw[0] and string2 with two[1]? If so:
is this part of the c standard?
do i have to cast the struct to an array first?
what about fields which are different sizes in memory
what about fields which are different types but the same size?
can you do pointer arithmetic within a structure?
-