Re: Adress of a struct vs address of its first field
From: Greg Comeau (comeau_at_panix.com)
Date: 03/14/05
- Next message: Ben Hutchings: "Re: Invalid suffix to floating constant"
- Previous message: Dr. Adrian Wrigley: "Re: Teaching new tricks to an old dog (C++ -->Ada)"
- In reply to: Grumble: "Adress of a struct vs address of its first field"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 14 Mar 2005 16:26:34 -0500
In article <d14h4r$ige$1@news-rocq.inria.fr>,
Grumble <devnull@kma.eu.org> wrote:
>Assume I have a plain, old, boring struct foo (i.e. no virtual
>functions, no methods, just data fields). Assume the first field is bar.
>
>struct foo s;
>
>Will &s == &(s.bar) always be true regardless of the type of bar?
In this case, yes.
>What if the type of bar is unsigned char[16]?
Still yes.
When and if possible, you should favor more portable techniques though.
For instance, since you're referring to PODs only, consider maybe
offsetof, or even just use the &'s as you've shown above.
-- Greg Comeau / Comeau for the Mac? Stay tuned. Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90. Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
- Next message: Ben Hutchings: "Re: Invalid suffix to floating constant"
- Previous message: Dr. Adrian Wrigley: "Re: Teaching new tricks to an old dog (C++ -->Ada)"
- In reply to: Grumble: "Adress of a struct vs address of its first field"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|