🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: "file selector" blues, Megamax bug

#26358
From: Jwahar R. Bammi
Date: Tue, 14 Apr 1987 03:07
44 lines
2420 bytes
In article <821@viper.UUCP> john@viper.UUCP (John Stanley) writes:
>In article <639@batcomputer.tn.cornell.edu>
> braner@tcgould.tn.cornell.edu.UUCP (braner) writes:
> >Yet another bug in Megamax C:
> >
> >	sizeof("a string constant") always yields 4.
>  As I mentioned before...  This is infact the right way for sizeof to
>work.  When you ask for sizeof(something) you're always asking how
>large that element is to the compiler.  The type reference is a reference
>to a type with a specific size...  The reference to the string is
>translated into a pointer before sizeof gets around to doing it's job.
>I agree that the latter is confusing, but it conforms to K&R page 94
>"... a reference to an array is converted by the compiler to a pointer
>to the beginning of the array." And to page 188 where the effects of
>using sizeof on a type identifier is described.  If you wanted to know
>how long the string is, you might want to use strlen instead...
>
>--- 

	i think you are quoting K&R page 94 a little bit out of context
(for the sizeof operator). The sizeof operator is evaluated at compile
time, and does not itself cause any usual conversions to be applied to
the expression in determining its type. If what you said were true, then
consider the following example

		char a[100];

		printf("%d\n",sizeof(a));

	Why should the sizeof a be 100 and not 4??
	Since "..." is nothing but an array of char, then it follows ....

	Another bug in MegaMax

		int b;
		sizeof(b+0L);
		^^^^^^^^^^^^
			Totally confuses the compiler.  MWC,Alcyon,Vax cc,
and Tartan tcc all correctly report 4.
-- 
usenet: {decvax,cbatt,cbosgd,sun}!cwruecmp!bammi	jwahar r. bammi
csnet:       bammi@case
arpa:        bammi%case@csnet-relay
compuServe:  71515,155
Technical Details
Message-ID: <2041@cwruecmp.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!columbia!rutgers!clyde!cbatt!cwruecmp!bammi
References: <639@batcomputer.tn.cornell.edu> <821@viper.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!columbia!rutgers!clyde!cbatt!cwruecmp!bammi
From: bammi@cwruecmp.UUCP (Jwahar R. Bammi)
Newsgroups: comp.sys.atari.st
Subject: Re: "file selector" blues, Megamax bug
Message-ID: <2041@cwruecmp.UUCP>
Date: Mon, 13-Apr-87 22:07:20 EST
Article-I.D.: cwruecmp.2041
Posted: Mon Apr 13 22:07:20 1987
Date-Received: Sat, 18-Apr-87 19:25:33 EST
References: <639@batcomputer.tn.cornell.edu> <821@viper.UUCP>
Reply-To: bammi@cwruecmp.UUCP (Jwahar R. Bammi)
Organization: Case Western Reserve University
Lines: 44
Keywords: user-friendly C sizeof