Shortcut for accessing build-in struct

K

kenchu.osu

Hi folks,

I have a question about accessing the member of a build-in struct.

Eg.

struct {
struct {
int x;
int y;
} pt;
int ...
...
} info;

I remember there is a method to simplify the access of info.pt.x using
info.x, but I cannot recall that. Can you guys help me with that?

Thanks a lot.

Best,
Ken
 
E

Eric Sosman

Hi folks,

I have a question about accessing the member of a build-in struct.

Eg.

struct {
struct {
int x;
int y;
} pt;
int ...
...
} info;

I remember there is a method to simplify the access of info.pt.x using
info.x, but I cannot recall that. Can you guys help me with that?

Some compilers allow "anonymous" struct elements, but
this is not permitted in Standard C (except for a special
case involving bit-fields, not applicable here).

You could play preprocessor games, like

#define X(s) ((s).pt.x)

.... but in my experience such tricks are usually more
trouble than they're worth.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top