🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #26307

Re: sizeof("string")

#26307
From: pett
Date: Tue, 14 Apr 1987 22:23
37 lines
1513 bytes
In article <2006@ihuxz.ATT.COM> burris@ihuxz.ATT.COM (Burris) writes:
|In article <8704120143.AA11235@cory.Berkeley.EDU>, dillon@CORY.BERKELEY.EDU (Matt Dillon) writes:
|> >>  sizeof("anystring") returns 4 (the size of the pointer!!!!), not 10.
|> >
|> >Excuse me, but this doesn't sound like a bug...  
|
|The first response was correct. That's why there's a strlen() function.
|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
|
|Dave Burris
|ihnp4!ihuxz!burris

Unfortunately, if you'd bothered to actually run your program (as I did
on our VAX 8600) you would have noticed the actual result:

20 
4
6

				Eric Pettersen
				pett@cgl.ucsf.edu
Technical Details
Message-ID: <10168@cgl.ucsf.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!ames!ucbcad!ucbvax!ucsfcgl!socrates.ucsf.edu!pett
References: <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!ames!ucbcad!ucbvax!ucsfcgl!socrates.ucsf.edu!pett
From: pett@socrates.ucsf.edu.UUCP
Newsgroups: comp.sys.atari.st
Subject: Re: sizeof("string")
Message-ID: <10168@cgl.ucsf.EDU>
Date: Tue, 14-Apr-87 17:23:42 EST
Article-I.D.: cgl.10168
Posted: Tue Apr 14 17:23:42 1987
Date-Received: Thu, 16-Apr-87 01:11:36 EST
References: <8704120143.AA11235@cory.Berkeley.EDU> <2006@ihuxz.ATT.COM>
Sender: daemon@cgl.ucsf.edu
Reply-To: pett@socrates.ucsf.edu (Eric F. Pettersen)
Organization: UCSF Computer Graphics Lab
Lines: 37