🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: "file selector" blues, Megamax bug

#26276
From: nowlin
Date: Mon, 13 Apr 1987 18:52
23 lines
1537 bytes
In article <639@batcomputer.tn.cornell.edu>, braner@batcomputer.tn.cornell.edu (braner) writes:
> []
> 
> Yet another bug in Megamax C:
> 
> 	sizeof("a string constant") always yields 4.
> 
> 	(sizeof(s) where s is of type array-of-char works fine.)
> 
> - Moshe Braner

Intuitively this looks like a place where you'd want to use strlen()
instead of sizeof().  I know sizeof() is faster.  It doesn't make as much
sense as strlen() in this context though.  I suspect that Megamax is
resolving the reference to a string constant as a (char *) which is of size
4.  It's almost funny but some of the 3B compilers also return 4 for this
operation and trying to solve the bug it introduced into our code was the
cause of much wailing and gnashing of teeth.  If you want the length of a
string use strlen().  Personally I think it's a bug if sizeof("string")
doesn't return the size of (char *).

Jerry Nowlin
(...!ihnp4!ihuxy!nowlin)
Technical Details
Message-ID: <1934@ihuxy.ATT.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!cbatt!ihnp4!ihuxy!nowlin
References: <639@batcomputer.tn.cornell.edu>

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!cbatt!ihnp4!ihuxy!nowlin
From: nowlin@ihuxy.UUCP
Newsgroups: comp.sys.atari.st
Subject: Re: "file selector" blues, Megamax bug
Message-ID: <1934@ihuxy.ATT.COM>
Date: Mon, 13-Apr-87 13:52:03 EST
Article-I.D.: ihuxy.1934
Posted: Mon Apr 13 13:52:03 1987
Date-Received: Wed, 15-Apr-87 01:50:04 EST
References: <639@batcomputer.tn.cornell.edu>
Organization: AT&T Bell Laboratories - Naperville, Illinois
Lines: 23
Keywords: user-friendly C sizeof
Summary: misuse of sizeof