Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Is this valid C? Date: Mon, 27 Feb 2017 12:12:33 -0800 Organization: None to speak of Lines: 35 Message-ID: References: <87mvdib11n.fsf@bsb.me.uk> <1befylefw1.fsf@pfeifferfamily.net> <87d1e4alzc.fsf@bsb.me.uk> <87r32js9yi.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="704c5d663da9e0150365451e4cbc43e2"; logging-data="9869"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18U4YKasFOoQsLSgu3IHVLJ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:qOwYhsPP3lumOX5Sn+qCZdPCnQE= sha1:tJw0SYZ4yXLdC7417PY1NzzjKQ0= Xref: csiph.com comp.lang.c:104922 Ben Bacarisse writes: > Ralf Damaschke writes: >> Ben Bacarisse schrieb: >>> sizeof *NULL >>> 0 && 1/0 >>> 0 ? 1 : 1/0 >>> >>> are all well-defined because the operator that, according to the "rule", >>> *should* be done first is not done at all. >> >> Sorry to jump in. >> However, the first example is not well-defined. Depending on the >> definition of NULL it's a constraint violation of either the indirection >> or the sizeof operator. > > Yes. Annoyingly, I changed it from > > sizeof *x // where x == NULL > > at the last minute just to avoid having to have a comment explain things > but I should have given it more thought. Thanks for picking that up. sizeof (*(int*)NULL) or sizeof (*(int*)0) would also work. And in your example, you're assuming that x is not of type void* (more generally, that it's a pointer to a complete object type). -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"