Path: utzoo!utgpu!watmath!clyde!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: NULL is not '\0' (was: Is malloc() or calloc() "better"?) Message-ID: <11375@haddock.ima.isc.com> Date: 9 Jan 89 18:00:34 GMT References: <9254@smoke.BRL.MIL> <620@usl.usl.edu> <11049@tiger.oxy.edu> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 16 In article <11049@tiger.oxy.edu> bagpiper@oxy.edu (Michael Paul Hunter) writes: >I think it would be better (and faster) to malloc and set the first element >of the array to (char)NULL if you want it to be a 0 length string. Right idea, wrong name. NULL is a null pointer constant. Please do not confuse it with the null character. If the built-in name '\0' isn't good enough, then call it NUL (with one L, as in the ASCII tables). For nearly accidental reasons, it is quite legal% to write '\0' when you mean a null pointer constant, though only an Obfuscated C contestant would do so. Using NULL when you mean a null character, however, is not guaranteed to work (even with the cast), since (in ANSI C) the macro might expand into (void *)0. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint ________ % Except in non-prototyped function arguments, where a cast is required.