Article View: comp.sys.atari.st
Article #26300Re: sizeof("string")
From: sansom
Date: Tue, 14 Apr 1987 17:17
Date: Tue, 14 Apr 1987 17:17
35 lines
1779 bytes
1779 bytes
In article <2006@ihuxz.ATT.COM> burris@ihuxz.ATT.COM (Burris) writes:
>bla, bla, bla, ...Now if it were as follows:
>char string[ 20 ];
>char *strpt = "hello";
>
>main()
>{
> printf( "%d\n", sizeof( string ) );
> printf( "%d\n", sizeof( strpt ) );
> printf( "%d\n", sizeof( "hello" ) );
>}
>the result would be:
>20
>4
>4
(This is getting out of hand) - I just ran your program on our 4.2 BSD
system and came up with the following results:
20
4
6
Our compiler is of the "portable" variety, so I would think that it is
generating "correct" code. Still, there clearly seems to be some fuzziness
out there regarding this type of "problem". Some compilers treat a string
literal (e.g., "hello") as an array, and some treat it as a pointer to an
array. I guess that's one of the reasons an ANSI standard C is in the works.
-Rich
--
/////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/// Richard E. Sansom TRW Electronics & Defense Sector \\\
\\\ {decvax,ucbvax,ihnp4}!trwrb!sansom Redondo Beach, CA ///
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/////////////////////////////////////
Technical Details
Message-ID:
<1765@trwrb.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!lll-lcc!ames!ucbcad!ucbvax!hplabs!sdcrdcf!trwrb!sansomReferences:
<8704120143.AA11235@cory.Berkeley.EDU> <2006@ihuxz.ATT.COM>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!lll-lcc!ames!ucbcad!ucbvax!hplabs!sdcrdcf!trwrb!sansom
From: sansom@trwrb.UUCP
Newsgroups: comp.sys.atari.st
Subject: Re: sizeof("string")
Message-ID: <1765@trwrb.UUCP>
Date: Tue, 14-Apr-87 12:17:39 EST
Article-I.D.: trwrb.1765
Posted: Tue Apr 14 12:17:39 1987
Date-Received: Wed, 15-Apr-87 05:46:47 EST
References: <8704120143.AA11235@cory.Berkeley.EDU> <2006@ihuxz.ATT.COM>
Reply-To: sansom@trwrb.UUCP (Richard Sansom)
Organization: TRW EDS, Redondo Beach, CA
Lines: 35