POV-Ray : Newsgroups : povray.off-topic : A puzzle about C (and probably C++)... : Re: A puzzle about C (and probably C++)... Server Time
3 Sep 2024 11:23:17 EDT (-0400)
  Re: A puzzle about C (and probably C++)...  
From: Le Forgeron
Date: 17 Feb 2011 14:28:50
Message: <4d5d76f2$1@news.povray.org>
Le 17/02/2011 19:29, Darren New nous fit lire :
> 
> Under what circumstances does it matter what order the members of a
> union are written in?  When does it make a difference as to which type
> inside the union is declared first?
> 
IBM extension: When you use zero-extent member in a union, it must be
the last "field".

e.g.

union Foo {
  int a;
  char b[0];
}

This syntax is supported by gcc too, but it does not care about the
order unless you want to initialise it. (for C99 and after)



typedef union {

  int a;
  long c;
  char b[0];

} Foo;

main()
{
	Foo k={257};
	printf("Hello %d %d\n",k.b[0],k.b[1]);
}


So, the first might not be always important (it is for initialisation at
declaration time), but the last would, on AIX at least.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.