Path: utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!tektronix!orca!tekecs!frip!andrew From: andrew@frip.gwd.tek.com (Andrew Klossner) Newsgroups: comp.lang.c Subject: Re: Null-terminated C strings Message-ID: <9565@tekecs.TEK.COM> Date: 24 Dec 87 18:51:08 GMT References: <174@quick.COM> <14116@think.UUCP> <2447@hall.cray.com> <3087@phri.UUCP> Sender: nobody@tekecs.TEK.COM Organization: Tektronix, Wilsonville, Oregon Lines: 23 [] "Should a \000 in a string constant be flagged as a warning by the compiler? ... I can't think of any valid reason offhand you would *want* to do such a thing." Character arrays have uses other than printable strings. The fact that \000 and eight-bit characters like \377 can be spelled in C leads to some useful coding shortcuts. As a (stupid) example: int isPrime(number) int number; { if (number<0 || number>10) { fprintf(stderr,"isPrime(%d): out of range\n",number); abort(); } return "\0\1\1\1\0\1\0\1\0\0\0"[number]; } (I have made non-stupid use of this feature, but in programs too long to use as examples here.) -=- Andrew Klossner (decvax!tektronix!tekecs!andrew) [UUCP] (andrew%tekecs.tek.com@relay.cs.net) [ARPA]