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 code considered to transgress the signed overflow purism? Date: Tue, 02 May 2017 15:27:53 -0700 Organization: None to speak of Lines: 53 Message-ID: References: <11ea6682-cdee-4513-97c2-6c90b585716a@googlegroups.com> <87o9vi6rql.fsf@bsb.me.uk> <26aee5e9-ed2f-4c6e-af68-b85418c7e641@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="19a76335ac2142e153f4288dee9a58f7"; logging-data="6042"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fKwbWCXsN66DZ47AR5XXK" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:0jT9ZY8uNxBP9SuKdALkJfgPvyM= sha1:L/NucI7l9CFBkWSX5g6/awLEqKI= Xref: csiph.com comp.lang.c:109062 bartc writes: > On 02/05/2017 22:10, Keith Thompson wrote: >> bartc writes: >>> However, it was suggested that such a type might give a different sizeof >>> result in a PP expression, compared with a normal expression. That's why >>> I asked for an example. >> >> Which I gave you. 1U is of type unsigned int. In a typical >> implementation, unsigned int might be 4 bytes, but it would be >> treated by the preprocessor as if it were 8 bytes. >> >> The simplest enhancement of the preprocessor to handle >> `sizeof (unsigned int)` would have it yield 8 -- which would not >> be useful. > > We might be talking at cross purposes. I don't believe we are. > The preprocessor is one thing; the parser and rest of the compiler is > another. Certainly. > How the preprocessors deals with #if expressions, and what type they > might have is its own business. > > But when you ask it to evaluate sizeof(int) (in a possible extension), > then that would necessarily have to be the size of the int used in the > rest of the compiler. As I acknowledged upthread (and you snipped): To make it useful, you'd have to make the preprocessor aware that unsigned int has a size of 4 bytes on the target system, overriding the current wording of 6.10.1p4. > As an illustration, what should be the sizeof() return here: > > #if sizeof(float)==4 For that construct to be at all useful, of course sizeof(float) should yield the same value that it yields in a non-preprocessor expression. The difficulty of rigorously defining that and then implementing it is probably why C doesn't currently define such a feature. [...] -- 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"