{char foo[]="This is a test."; printf("%d\n",sizeof foo);}

Wayne A. Throop throopw at xyzzy.UUCP
Sat Apr 16 01:53:39 AEST 1988


> emiller at bbn.com (ethan miller)
>> ok at quintus.UUCP (Richard A. O'Keefe)
>>> major at eleazar.Dartmouth.EDU (Lou Major)
>>> char foo[]="This is a test.";
>>> sizeof (foo) == sizeof (char *)
>>Wrong.  The answer *is* 16.  [...assuming sizeof(char)==1, but let's
>>not get into that...]  This is one of the few cases where
>>foo and &(foo[0]) are different.
> What did you try?  _I_ just tried printing foo and &(foo[0]), and
> they are the same.  BTW, I also tried sizeof (foo), and it is 16.

>From the context, I assumed that by "This is one of the few cases where
foo and &foo[0] are different", Richard meant "(sizeof foo) and (sizeof
(&foo[0])) may give different results", which is quite correct.  For
example:

        $ cat >test.c <<.
        char foo[]="This is a test.";
        main(){}
        .
        $ cc -g test.c
        $ dbx a.out
        Scanning executable file...
        (dbx) whatis foo
        char foo[16];
        (dbx) print (sizeof foo)
        16
        (dbx) print (sizeof &foo[0])
        4
        (dbx) quit
        $

--
If the argument to .TH contains any blanks and is not enclosed by double
quotes, there will be dird-dropping-like things on the output.
                                --- Unix User's Manual, MAN(7) entry, BUGS
-- 
Wayne Throop      <the-known-world>!mcnc!rti!xyzzy!throopw



More information about the Comp.lang.c mailing list