Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.unix.programmer,comp.lang.c Subject: Re: Odd compiler behaviour? Date: Tue, 01 Mar 2016 08:45:24 -0800 Organization: None to speak of Lines: 47 Message-ID: References: <20160301061135.783@kylheku.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="27485"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Jkjl+T0VOzO173Z+GapDK" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:jhHCqSZ2q7SQLxeeUJeeGLkooTw= sha1:YCZMxcg8pGo82WvageGcGEz7K3o= Xref: csiph.com comp.unix.programmer:7964 comp.lang.c:82868 spud@potato.field writes: > On Tue, 1 Mar 2016 14:15:16 +0000 (UTC) > Kaz Kylheku <330-706-9395@kylheku.com> wrote: >>On 2016-03-01, spud@potato.field wrote: >>> On Tue, 01 Mar 2016 13:03:56 +0000 >>> Richard Kettlewell wrote: >>>>Undefined. C99 6.5.7#4: >>> >>> That seems an odd decision to make. Its not undefined when you do an >>> assembly left shift in most CPUs AFAIK - you get zero or a wrap if >>> you use a rotate - >>so >> >>Well, that's part of the problem, isn't it? >> >>It's well-defined for each of the instruction sets (that you know) >>*individually*, but not for assembly language as such. > > Ok, but why not just define it anyway to give a certain result > irrespective of what various CPUs do for the sake of portability? For one thing, because specifying one particular behavior would require compilers to generate inefficient code even for cases with well-defined behavior. Suppose x is a 32-bit unsigned integer, and y has a value in the range 0..31 but the compiler is unable to prove it. The current definition (leaving x<<32 undefined) lets the compiler implement x< C data types are > defined to be a specific size and have a specific range regardless of > whether all possible processors support them natively so I don't see > why it couldn't be done for this. I'm not sure what you mean by that. Type int, for example, has a specific size and range for each implementation, but it varies across implementations. It's required to have a range of at least -32767..+32767. -- 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"