View Single Post
  #4   Spotlight this post!  
Unread 19-05-2007, 01:09
EricVanWyk EricVanWyk is offline
Registered User
no team
 
Join Date: Jan 2007
Rookie Year: 2000
Location: Boston
Posts: 1,597
EricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond repute
Send a message via AIM to EricVanWyk
Re: C Programming Homework Help Needed

I'm a bit confused as to exactly how this code compiled, and why it isn't happy. I know exactly enough C to confuse myself.

I understand why the code is wrong. I don't fully understand why this is the error that is given.

Since printf takes a variable number of untyped objects, I'll believe that it can't catch the type mismatch of address and float. This must be the case, since it did compile. Since C has no run-time environment to speak of, we must assume that the computer will do exactly what it is told: Take the address and interpret it as a float.

The code then loosely translates to:
Code:
float time;
int * backdoor = &time;
*backdoor = "integer value of the address of the variable time"
print time;
At this point we essentially have "take a random bit string and interpret it as a float". Why is this float NaN? I know that the float space does have NaN gaps, but I thought the space was relatively dense. In otherwords, I thought it was so dense that the probability of this error should be rather small. Does it happen repeatably? Is there something about the addressing space that places variables in the realm of NaN?

I may be reading too far into this, but I'd really appreciate the assistance of someone with a deeper understanding of C.

Thanks
Eric