Re: C to Java Byte Code
Old Wolf coughed up:[color=blue]
> Paul Lutus <nospam@nosite. zzz> wrote:[color=green]
>> Show us the bytecode that overlays a Java float and a Java integer
>> into the same memory space. That is what a union is.[/color]
>
> Sorry, you are wrong. There is no requirement in the C standard for
> the members of the union to occupy the same piece of memory.
> If you disagree then please quote a standard reference.
> (They must all return the same thing when their address is
> taken and then converted to (void *), but it does not follow
> from that that they occupy the same physical memory).
>[color=green]
>> Show us the Java bytecode that allows one to manipulate
>> individual bits of a Java float datatype, as a C union allows.[/color]
>
> A C union does not allow that. Any C program that
> relies on it is non-portable.
>
> The following results are conforming to the C specification
> (note, this is a minor modification of a program posted
> elsewhere in the thread):
>
> #include <stdio.h>
>
> typedef union abc
> { int x;
> float y;
> } a_union;
>
> main()
> { a_union z;
>[/color]
First example:[color=blue]
> z.x = 1;
> printf("int val = %d\n", z.x);
> printf("float val = %f\n", z.y);
>[/color]
Second example:[color=blue]
> z.y = 3.142;
> printf("int val = %d\n", z.x);
> printf("float val = %f\n", z.y);
> return 0;
> }
>
> Results:
> int val = 1
> float val = 3.142
> int val = 1
> float val = 3.142[/color]
How does the mini-PI come out of a union (first example) that was only set
with integer 1?
How does a 1 get pulled out of a union set with a value of mini-PI? A
/structure would do that at this point, since .x was set to 1, but not a
union.
Unless I'm going nuts here (possible)...
--
Framsticks. 3D Artificial Life evolution. You can see the creatures
that evolve and how they interact, hunt, swim, etc. (Unaffiliated with
me). http://www.frams.alife.pl/
Old Wolf coughed up:[color=blue]
> Paul Lutus <nospam@nosite. zzz> wrote:[color=green]
>> Show us the bytecode that overlays a Java float and a Java integer
>> into the same memory space. That is what a union is.[/color]
>
> Sorry, you are wrong. There is no requirement in the C standard for
> the members of the union to occupy the same piece of memory.
> If you disagree then please quote a standard reference.
> (They must all return the same thing when their address is
> taken and then converted to (void *), but it does not follow
> from that that they occupy the same physical memory).
>[color=green]
>> Show us the Java bytecode that allows one to manipulate
>> individual bits of a Java float datatype, as a C union allows.[/color]
>
> A C union does not allow that. Any C program that
> relies on it is non-portable.
>
> The following results are conforming to the C specification
> (note, this is a minor modification of a program posted
> elsewhere in the thread):
>
> #include <stdio.h>
>
> typedef union abc
> { int x;
> float y;
> } a_union;
>
> main()
> { a_union z;
>[/color]
First example:[color=blue]
> z.x = 1;
> printf("int val = %d\n", z.x);
> printf("float val = %f\n", z.y);
>[/color]
Second example:[color=blue]
> z.y = 3.142;
> printf("int val = %d\n", z.x);
> printf("float val = %f\n", z.y);
> return 0;
> }
>
> Results:
> int val = 1
> float val = 3.142
> int val = 1
> float val = 3.142[/color]
How does the mini-PI come out of a union (first example) that was only set
with integer 1?
How does a 1 get pulled out of a union set with a value of mini-PI? A
/structure would do that at this point, since .x was set to 1, but not a
union.
Unless I'm going nuts here (possible)...
--
Framsticks. 3D Artificial Life evolution. You can see the creatures
that evolve and how they interact, hunt, swim, etc. (Unaffiliated with
me). http://www.frams.alife.pl/
Comment