Path: utzoo!utgpu!water!watmath!clyde!bellcore!faline!ulysses!allegra!mit-eddie!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.UUCP Newsgroups: comp.lang.c Subject: Re: ! operator in constant expressions Message-ID: <7047@brl-smoke.ARPA> Date: 12 Jan 88 00:28:30 GMT References: <3813@hoptoad.uucp> <7027@brl-smoke.ARPA> Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 25 Posted: Mon Jan 11 19:28:30 1988 In article <7027@brl-smoke.ARPA>, I wrote: > In article <3813@hoptoad.uucp> gnu@hoptoad.uucp (John Gilmore) writes: > >int bar = !3.14156; > >int pno = ! &bar; > >int pyes = !(char *)0; > I don't see how you could expect any of these three to work; the > operand of ! has to be an integer ... My only excuse is that I was very ill when I wrote that! Of course, one all the time sees code like type *p; if (!p) ... My personal practice is to apply ! only to "Boolean expressions", which is not something that C officially understands, but it's easy to self-impose the "Boolean" discipline, and beneficial to code quality and maintenance. However, just because I never apply ! to a non-integer (which is a superset of Boolean in C), doesn't mean that it is prohibited by the language spec. Now that I can check the dpANS, I find that an initializer for a scalar is constrained to be a constant-expression, and otherwise the same type constraints and conversions apply as for simple assignment. Also, !E is equivalent to E==0. Thus, all the above examples are supposedly legal in ANSI C. I apologize for my earlier mistake.