Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* OSF/ALPHA C compiler bug
@ 1993-12-17 19:18 Guojun Jin[ITG]
  1993-12-17 19:55 ` David J. MacKenzie
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Guojun Jin[ITG] @ 1993-12-17 19:18 UTC (permalink / raw)


============================== test.c ====================================
include <stdio.h>
 
main()
{
float   f=0.0;
char    *cp;
int     *ip=(int*)&cp;
        *ip = f;
if (cp != NULL)
        printf("cp is not NULL, but -> %d\n", cp);
printf("Cp is %u\n", cp);
}
 
============================== end of test.c ================================
alpha1: cc -g test.c
alpha1: a.out
cp is not NULL, but -> 0
Cp is 0
 
What is the cp value?
 
/---------------------------------------v-------------------------------\
|	Jin Guojun, Imaging Technology	| Internet: g_jin@lbl.gov	|
|	Lawrence Berkeley Laboratory	| Usenet: ucbvax!g_jin@lbl.gov	|
|			| Bitnet:	jin%george.lbl.gov@Csa3.LBL.Gov	|


^ 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
                   ` (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

end of thread, other threads:[~1994-01-13 21:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` OSF/ALPHA C compiler bug Dennis Murphy
1994-01-13 21:44 ` Dennis Murphy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox