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:21:57 EDT (-0400)
  Re: A puzzle about C (and probably C++)...  
From: Darren New
Date: 18 Feb 2011 12:16:05
Message: <4d5ea955$1@news.povray.org>
Darren New wrote:
> I'll post the answer tomorrow morning. :-)

The answer I was *thinking* was when the native bit pattern for a "zero" 
value isn't all zeros for one or more of the basic types.

For example, I worked on an AT&T 3B2 for a while, where the bit pattern for 
NULL was 0x80000000.  So

static union { void* p, long l } x;
static union { long l, void* p } y;

would wind up with different values for x.l and y.l even before any 
assignments.  The same could happen with floats/doubles being first, if 
you're not using IEEE754.

The standard says a static union is initialized to the zero value for the 
first element.  I got curious once and actually tracked it down in the standard.

-- 
Darren New, San Diego CA, USA (PST)
  "How did he die?"   "He got shot in the hand."
     "That was fatal?"
          "He was holding a live grenade at the time."


Post a reply to this message

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