Path: utzoo!attcan!uunet!auspex!guy From: guy@auspex.UUCP (Guy Harris) Newsgroups: comp.lang.c Subject: Re: hardcoded constants Message-ID: <735@auspex.UUCP> Date: 17 Dec 88 05:02:13 GMT References: <1988Dec8.173158.11839@utzoo.uucp> <846@starfish.Convergent.COM> <33604@think.UUCP> <2478@ficc.uu.net> Reply-To: guy@auspex.UUCP (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 41 >How about sizeof "/"? Or does that return sizeof(char *)? No, it returns the number of bytes in the anonymous character array that "/" is. K&R First Edition says "When applied to an array, the result is the number of bytes in the array", and also A string is a sequence of character surrounded by double quotes, as in "...". A string has type "array of characters"... so "/" is an array, and "sizeof", when applied to it, returns the number of characters in it. The dpANS says much the same thing. Unfortunately or fortunately, depending on how you look at it, 'sizeof "/"' is 2, since the array in question has *two* characters - the '/' and the '\0' at the end. This means that strlen(a) + sizeof "/" + strlen(b) happens to be the minimum number of characters that must be in the array "buf" to make strcpy(buf, a); strcat(buf, "/"); strcat(buf, b); work, since it counts both the "/" added by the first "strcat" and the null left at the end; however strlen(a) + sizeof "/" + strlen(b) + sizeof "/" + strlen(c) is one more than the minimum number of characters that must be in the array "buf" to make strcpy(buf, a); strcat(buf, "/"); strcat(buf, b); strcat(buf, "/"); strcat(buf, c); work. In this particular case it may not be worth worrying about since it's only one character....