Article View: comp.sys.amiga.tech
Article #6958Re: C compilers code generation
From: Bruce Albrecht
Date: Mon, 19 Nov 1990 22:19
Date: Mon, 19 Nov 1990 22:19
26 lines
1959 bytes
1959 bytes
>In article <dillon.7260@overload.Berkeley.CA.US> dillon@overload.Berkeley.CA.US (Matthew Dillon) writes:
>In article <1990Nov15.170810.5868@sisd.kodak.com> jeh@sisd.kodak.com (Ed Hanway) writes:
>>__builtin_strlen() is definitely useful. SAS/C evaluates
>>strlen("string constant") at compile time. I don't know how good the
>>builtin versions of the other functions are, but if the compiler knows
>>anything about arguments to the function at compile time, it can
>>use different versions of the move/set code for small/large size,
>>aligned/unaligned, etc. If no information is available, it can always
>>call the general routine.
>
> Uh, I NEVER use strlen() on a string constant. That's the most
> ridiculous thing I've ever heard of in my life!
>
> I use (sizeof("string-constant") - 1). And, if you are worried about
> things looking 'neat', simply write a little preprocessor macro to do
> it.
If the string constant is created via #define, it's probably not a good idea to use
sizeof() to get its length. The #define could later be replaced by a char array,
and the sizeof() would not produce correct result if the actual string length was
smaller than the size of the array. The sizeof would still be syntatically correct,
and possibly difficult to locate.
--
bruce@zuhause.mn.org
Technical Details
Message-ID:
<bruce.4436@zuhause.MN.ORG>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!princeton!udel!wuarchive!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!src.honeywell.com!msi.umn.edu!cs.umn.edu!kksys!orbit!zuhause!bruceReferences:
<1990Nov12.164804.5490@agate.berkeley.edu> <26893.273fe96d@kuhub.cc.ukans.edu> <dillon.7256@overload.Berkeley.CA.US> <1990Nov15.170810.5868@sisd.kodak.com> <dillon.7260@overload.Berkeley.CA.US>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!princeton!udel!wuarchive!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!src.honeywell.com!msi.umn.edu!cs.umn.edu!kksys!orbit!zuhause!bruce From: bruce@zuhause.MN.ORG (Bruce Albrecht) Newsgroups: comp.sys.amiga.tech Subject: Re: C compilers code generation Message-ID: <bruce.4436@zuhause.MN.ORG> Date: 19 Nov 90 22:19:07 GMT References: <1990Nov12.164804.5490@agate.berkeley.edu> <26893.273fe96d@kuhub.cc.ukans.edu> <dillon.7256@overload.Berkeley.CA.US> <1990Nov15.170810.5868@sisd.kodak.com> <dillon.7260@overload.Berkeley.CA.US> Lines: 26