Path: 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: Date: 19 Nov 90 22:19:07 GMT References: <1990Nov12.164804.5490@agate.berkeley.edu> <26893.273fe96d@kuhub.cc.ukans.edu> <1990Nov15.170810.5868@sisd.kodak.com> Lines: 26 >In article 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