Re: C to Java Byte Code
On Wed, 27 Oct 2004 10:06:18 -0700
"Galga" <none@none.spam blowz> wrote:
[color=blue]
> Gerry Quinn wrote:[color=green]
> > In article <MPG.1be9e02545 c89c61989a6d@ne ws.indigo.ie>,
> > gerryq@DELETETH ISindigo.ie says...[color=darkred]
> >> In article <417E469B.95A63 564@yahoo.com>, cbfalconer@yaho o.com
> >> says...
> >>> Mohd Hanafiah Abdullah wrote:
> >>
> >>>> main()
> >>>> { a_union z;
> >>>>
> >>>> z.x = 1078531719;
> >>>> printf("int val = %d\n", z.x);
> >>>> printf("float val = %f\n", z.y);
> >>>
> >>> illegal statement here. You cannot access a field of a union as a
> >>> type other than what you last wrote into it.
> >>
> >> It's not illegal, any more than casting a float to an int (which it
> >> effectively is) is illegal.[/color]
> >
> > Sorry, I meant casting a float* to an int* and de-referencing.
> > Casting a float to an int does give specified results, of course.[/color]
>
> Good catch, I was about to reply about that, saved me the trouble :-)[/color]
I caught my reply on the outgoing spool before it left.
However, the bit pattern of an int can be a trap representation for a
float, so writing an int then reading it as a float is definitely *not*
guaranteed to leave your program running. I think the only type punning
the C standard actual guarantees won't crash your program is reading
anything as unsigned char, an exception that I believe is explicitly
mentioned.
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
On Wed, 27 Oct 2004 10:06:18 -0700
"Galga" <none@none.spam blowz> wrote:
[color=blue]
> Gerry Quinn wrote:[color=green]
> > In article <MPG.1be9e02545 c89c61989a6d@ne ws.indigo.ie>,
> > gerryq@DELETETH ISindigo.ie says...[color=darkred]
> >> In article <417E469B.95A63 564@yahoo.com>, cbfalconer@yaho o.com
> >> says...
> >>> Mohd Hanafiah Abdullah wrote:
> >>
> >>>> main()
> >>>> { a_union z;
> >>>>
> >>>> z.x = 1078531719;
> >>>> printf("int val = %d\n", z.x);
> >>>> printf("float val = %f\n", z.y);
> >>>
> >>> illegal statement here. You cannot access a field of a union as a
> >>> type other than what you last wrote into it.
> >>
> >> It's not illegal, any more than casting a float to an int (which it
> >> effectively is) is illegal.[/color]
> >
> > Sorry, I meant casting a float* to an int* and de-referencing.
> > Casting a float to an int does give specified results, of course.[/color]
>
> Good catch, I was about to reply about that, saved me the trouble :-)[/color]
I caught my reply on the outgoing spool before it left.
However, the bit pattern of an int can be a trap representation for a
float, so writing an int then reading it as a float is definitely *not*
guaranteed to leave your program running. I think the only type punning
the C standard actual guarantees won't crash your program is reading
anything as unsigned char, an exception that I believe is explicitly
mentioned.
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
Comment