Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: sizeof(char) Message-ID: <5356@brl-smoke.ARPA> Date: Tue, 11-Nov-86 08:05:07 EST Article-I.D.: brl-smok.5356 Posted: Tue Nov 11 08:05:07 1986 Date-Received: Tue, 11-Nov-86 20:11:28 EST References: <4617@brl-smoke.ARPA> <657@dg_rtp.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 25 In article <5355@brl-smoke.ARPA> I wrote: > use of sizeof"string_constant" instead of > strlen("string_constant")+1 : occurs in about 10 places (I had to > find all these once, since an older Gould compiler insisted that > sizeof"string_constant"==sizeof(char *) .) It occurs to me that if I don't add the following, someone will undoubtedly pick up on a point that would result in even more net traffic: I deliberately didn't show the simpler, more efficient fix of using sizeof"string_constant"/sizeof(char) because that wasn't helpful for the Gould compiler's problem. However, if one's compiler can be counted on to work, this latter is a much better fix. Both approaches are also correct for pre-X3J11 C compilers. The important thing to notice is that you can prepare your code NOW for any possible future transition to a compiler that doesn't assume sizeof(char)==1. I highly recommend this whether or not my proposal is adopted, since it helps to maintain the CONCEPTUAL distinction between characters and memory storage unit cells, much as I recommend writing C code AS THOUGH the C language (like Algol) distinguished between Booleans and ints. We shouldn't have to argue the merits of data abstraction here, since that is taught in basic computer science courses (according to what I hear -- there weren't any such courses when I first got into this business, since we were busy inventing the discipline).