Re: Identifying a structure by reading it's first field.
- From: Ernie Wright <erniew comcast net>
- To: gtk-app-devel-list gnome org
- Subject: Re: Identifying a structure by reading it's first field.
- Date: Sat, 02 Jun 2012 00:04:18 -0400
On 6/1/2012 2:17 PM, Osmo Antero wrote:
I have couple of C structures that I want to distinguish between by
reading the structures' first (type) field. [...]
Q: Can I assume that the "type" field is always first in the
structures, so I can read it with: NodeType type = *(NodeType*)node;
Yes. Structure members are stored in the order in which they're
defined, and a pointer to a structure also points to its first member
(suitably cast). This is guaranteed by the C standards.
but can I trust it on all *nix plattforms and GCC compilers.
Anything that's standards-compliant.
- Ernie http://home.comcast.net/~erniew
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]