* Re: OSF/ALPHA C compiler bug
1993-12-17 19:18 OSF/ALPHA C compiler bug Guojun Jin[ITG]
@ 1993-12-17 19:55 ` David J. MacKenzie
1993-12-17 21:46 ` OSF/ALPHA C compiler bug (not!) Daniel S. Riley
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: David J. MacKenzie @ 1993-12-17 19:55 UTC (permalink / raw)
Use %ld and %lu to print pointers on the alpha, not %ld and %lu, which
only print the low 32 bits. Then you get (or at least I get):
cp is not NULL, but -> 4294967296
Cp is 4294967296
Automatic variables aren't guaranteed to be initialized to anything in
particular, anyway, so there's no bug except in your little program.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: OSF/ALPHA C compiler bug (not!)
1993-12-17 19:18 OSF/ALPHA C compiler bug Guojun Jin[ITG]
1993-12-17 19:55 ` David J. MacKenzie
@ 1993-12-17 21:46 ` Daniel S. Riley
1994-01-13 21:38 ` OSF/ALPHA C compiler bug Dennis Murphy
1994-01-13 21:44 ` Dennis Murphy
3 siblings, 0 replies; 5+ messages in thread
From: Daniel S. Riley @ 1993-12-17 21:46 UTC (permalink / raw)
In article <2et0mf$1v3@overload.lbl.gov>,
jin@gracie.lbl.gov (Guojun Jin[ITG]) writes:
Guojun> float f=0.0;
Guojun> char *cp;
Guojun> int *ip=(int*)&cp;
Guojun> *ip = f;
Guojun> if (cp != NULL)
Guojun> printf("cp is not NULL, but -> %d\n", cp);
Guojun> printf("Cp is %u\n", cp);
Those should be
if (cp != NULL)
printf("cp is not NULL, but -> %ld\n", cp);
printf("Cp is %lu\n", cp);
remember, sizeof (char *) > sizeof (int). %d interprets the object
as an int, which only shows you half of cp. Similarly, *ip only sets
half of cp, as you'll discover when you get the printf() formats right.
In short, not a compiler bug.
--
-Dan Riley Internet: dsr@lns598.tn.cornell.edu
-Wilson Lab, Cornell University HEPNET/SPAN: lns598::dsr (44630::dsr)
"Distance means nothing/To me." -Kate Bush
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: OSF/ALPHA C compiler bug
1993-12-17 19:18 OSF/ALPHA C compiler bug Guojun Jin[ITG]
1993-12-17 19:55 ` David J. MacKenzie
1993-12-17 21:46 ` OSF/ALPHA C compiler bug (not!) Daniel S. Riley
@ 1994-01-13 21:38 ` Dennis Murphy
1994-01-13 21:44 ` Dennis Murphy
3 siblings, 0 replies; 5+ messages in thread
From: Dennis Murphy @ 1994-01-13 21:38 UTC (permalink / raw)
I've modified the test program as follows:
main()
{
int i1;
float f=0.0;
char *cp;
int *ip=(int*)&cp;
*ip = f;
if (cp != NULL)
printf("cp is not NULL, but -> 0x%lx\n", cp);
printf("size of ptr is %d, size of int is %d\n", sizeof(cp), sizeof(i1) );
and get the output
cp is not NULL, but -> 0x100000000
size of ptr is 8, size of int is 4
I hope that this helps.
Dennis Murphy
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: OSF/ALPHA C compiler bug
1993-12-17 19:18 OSF/ALPHA C compiler bug Guojun Jin[ITG]
` (2 preceding siblings ...)
1994-01-13 21:38 ` OSF/ALPHA C compiler bug Dennis Murphy
@ 1994-01-13 21:44 ` Dennis Murphy
3 siblings, 0 replies; 5+ messages in thread
From: Dennis Murphy @ 1994-01-13 21:44 UTC (permalink / raw)
With the program altered as follows:
main()
{
int i1;
float f=0.0;
char *cp;
int *ip=(int*)&cp;
*ip = f;
if (cp != NULL)
printf("cp is not NULL, but -> 0x%lx\n", cp);
printf("size of ptr is %d, size of int is %d\n", sizeof(cp), sizeof(i1) );
}
I get the results:
cp is not NULL, but -> 0x100000000
size of ptr is 8, size of int is 4
I hope that this helps:
Dennis Murphy
^ permalink raw reply [flat|nested] 5+ messages in thread