Article View: comp.bugs.misc
Article #154Re: Need help with C bug.
From: Daniel B. Suthers
Date: Sat, 01 Apr 1989 00:27
Date: Sat, 01 Apr 1989 00:27
32 lines
1518 bytes
1518 bytes
>Has anyone isolated the following pcc2 bug? (I assume it is a bug.)
>We have a Mot SVR2 based compiler.
> char p[50];
> main()
> {
> printf("p = 0x%08X\n", p);
> if (p)
> printf("ok\n");
> else
> printf("bad berries\n");
> }
>When run, this it says:
> p = 0x00002F84
> bad berries
>Any pointers?
It seems that your interpretation of what "p" is changes from statement to
statement. In the printf(), p is interpreted as a hexadecimal number, and
you are actually printing the address of p. (see "The C Programming Language",
Chapter 4.3: "when an array name appears as an argument to a function, the
location of the beginning of the array is passed")
At a guess:
In the if() test you are looking at (probably) the hi order byte represented
by the address of p[0]; this appears to be 0x0000.
Do you really want to check to ensure that there is a value stored at &p[0]?
( if(p[0]) ) or do you want to ensure you have an array ( if(p != NULL) )
Dan Suthers, Systems Analyst;
Technical Details
Message-ID:
<24971@pbhya.PacBell.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!ames!pacbell!pbhya!dbsutherReferences:
<349@iconsys.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!ames!pacbell!pbhya!dbsuther From: dbsuther@PacBell.COM (Daniel B. Suthers) Newsgroups: comp.bugs.misc Subject: Re: Need help with C bug. Keywords: pcc2 char array code generation Message-ID: <24971@pbhya.PacBell.COM> Date: 1 Apr 89 00:27:59 GMT References: <349@iconsys.UUCP> Reply-To: dbsuther@PacBell.COM (Daniel B. Suthers) Distribution: usa Organization: Pacific * Bell, San Ramon, CA Lines: 32