referencing struct fields in c with square brackets and an index instead of . and ->?
Posted
by
lsiebert
on Stack Overflow
See other posts from Stack Overflow
or by lsiebert
Published on 2012-06-05T21:48:32Z
Indexed on
2012/06/05
22:40 UTC
Read the original article
Hit count: 107
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? -
© Stack Overflow or respective owner