Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Shortcut for accessing build-in struct

Reply
Thread Tools

Shortcut for accessing build-in struct

 
 
kenchu.osu@gmail.com
Guest
Posts: n/a
 
      10-29-2007
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

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      10-29-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote On 10/29/07 11:55,:
> 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.

--
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
Shortcut, And Re-Directing Of Shortcut Quest. ? Robert11 Computer Support 1 12-30-2004 03:13 PM
struct in struct Gunnar G C++ 14 06-02-2004 06:43 PM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM
implementing a templated struct within a templated struct RA Scheltema C++ 3 01-06-2004 11:25 AM



Advertisments