Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #108699

Re: https://github.com/bartg/langs/tree/master/bccproj

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: https://github.com/bartg/langs/tree/master/bccproj
Date 2017-04-28 14:57 -0700
Organization None to speak of
Message-ID <ln1ssckxes.fsf@kst-u.example.com> (permalink)
References (9 earlier) <e3c2713d-383d-400b-a20c-f0f7c0a70839@googlegroups.com> <odvv0q$sl8$1@dont-email.me> <25ef1787-5f5c-428e-96e6-1acdbfb6aeba@googlegroups.com> <lnbmrgl4mv.fsf@kst-u.example.com> <oe085f$tpl$1@dont-email.me>

Show all headers | View raw


David Brown <david.brown@hesbynett.no> writes:
> On 28/04/17 21:21, Keith Thompson wrote:
[...]
>> Here's the wording from the C++11 standard, discussing E1 << E2
>> (changing some of the punctuation to avoid non-ASCII characters):
>>
>>     Otherwise, if E1 has a signed type and non-negative value,
>>     and E1 * 2**E2 is representable in the result type, then that
>>     is the resulting value; otherwise, the behavior is undefined.
>>
>> The N4296 draft of C++17 says:
>>
>>     Otherwise, if E1 has a signed type and non-negative value, and
>>     E1 * 2**E2 is representable in the corresponding unsigned type of
>>     the result type, then that value, converted to the result type,
>>     is the resulting value; otherwise, the behavior is undefined.
>>
>> I don't know why that change was made.
>
> I'd been looking at the C++11 standard - it had not occurred to me that 
> there would be such a change between standard versions.

I found the C++ DR that triggered the change.

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1457

The rationale given in the DR is:

    As a result, this technique cannot be used in a constant expression,
    which will break a significant amount of code.

>> To answer your original question, a C++ implementation that uses
>> C intermediate code must do whatever is necessary to ensure that
>> it behaves in accordance with whichever C++ standard it claims to
>> support.  That might or might not involve some extra work for the
>> "<<" operator with a signed left operand.  I have no idea what any
>> such implementations actually do.
>>
>
> gcc has this to say about integers:
>
>> The results of some bitwise operations on signed integers (C90 6.3,
>> C99 and C11 6.5).
>>
>> Bitwise operators act on the representation of the value including
>> both the sign and value bits, where the sign bit is considered
>> immediately above the highest-value value bit. Signed ">>" acts on
>> negative numbers by sign extension.
>>
>> As an extension to the C language, GCC does not use the latitude
>> given in C99 and C11 only to treat certain aspects of signed "<<" as
>> undefined. However, -fsanitize=shift (and -fsanitize=undefined) will
>> diagnose such cases. They are also diagnosed where constant
>> expressions are required.
>
> That last paragraph does not sound very clear to me.  Did the behaviour 
> of signed << change between C90 and C99 ?

C90 says:

    The result of E1 << E2 is E1 left-shifted E2 bit positions;
    vacated bits are filled with zeros. If E1 has an unsigned
    type, the value of the result is E1 multiplied by the quantity,
    2 raised to the power E2, reduced modulo ULONG_MAX+1 if E1
    has type unsigned long, UINT-MAX+1 otherwise. (The constants
    ULONG_MAX and UINT_MAX are defined in the header <limits.h>.)

C99 says (and C11 is identical) (I've changed some of the punctuation
to avoid non-ASCII characters):

    The result of E1 << E2 is E1 left-shifted E2 bit positions;
    vacated bits are filled with zeros. If E1 has an unsigned type,
    the value of the result is E1 * 2^E2, reduced modulo one more
    than the maximum value representable in the result type. If
    E1 has a signed type and nonnegative value, and E1 * 2^E2 is
    representable in the result type, then that is the resulting
    value; otherwise, the behavior is undefined.

The wording for the maximum value of an unsigned type was made more
general due to C99's addition of long long, and the final sentence:

    If E1 has a signed type and nonnegative value, and E1 * 2^E2 is
    representable in the result type, then that is the resulting value;
    otherwise, the behavior is undefined.

was added by C99.  It's difficult to say what C90's intent was when E1
is negative.  I'd say that sentence was added precisely because the C90
wording was unclear.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
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"

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

https://github.com/bartg/langs/tree/master/bccproj jacobnavia <jacob@jacob.remcomp.fr> - 2017-04-24 23:33 +0200
  Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-04-24 23:14 +0100
    Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-04-25 00:31 +0100
    Re: https://github.com/bartg/langs/tree/master/bccproj scott@slp53.sl.home (Scott Lurndal) - 2017-04-25 14:46 +0000
      Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-04-25 17:05 +0100
        Re: https://github.com/bartg/langs/tree/master/bccproj Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-26 01:32 +0100
          Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-04-26 11:32 +0100
            Re: https://github.com/bartg/langs/tree/master/bccproj Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-26 12:09 +0100
              Re: https://github.com/bartg/langs/tree/master/bccproj Tim Rentsch <txr@alumni.caltech.edu> - 2017-04-27 14:32 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-04-28 06:23 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj scott@slp53.sl.home (Scott Lurndal) - 2017-04-28 14:26 +0000
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-04-28 11:04 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj scott@slp53.sl.home (Scott Lurndal) - 2017-04-28 18:26 +0000
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-04-28 12:59 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj scott@slp53.sl.home (Scott Lurndal) - 2017-04-28 20:29 +0000
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-04-28 17:35 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-04-28 13:21 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-04-28 22:35 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-05-01 05:16 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-05-01 13:47 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-05-03 05:16 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-05-05 18:46 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-05-06 12:00 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj David Kleinecke <dkleinecke@gmail.com> - 2017-05-06 12:01 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-05-06 12:15 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj David Kleinecke <dkleinecke@gmail.com> - 2017-05-06 14:03 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-05-08 05:53 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-05-08 14:26 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-05-08 07:10 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-05-08 15:36 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-05-08 15:43 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj David Kleinecke <dkleinecke@gmail.com> - 2017-05-08 12:06 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-05-08 11:02 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-05-08 19:46 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-05-08 12:23 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-05-08 21:08 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-05-08 13:26 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Keith Thompson <kst-u@mib.org> - 2017-05-08 13:32 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-05-08 13:40 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-05-08 21:33 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-05-08 13:30 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-05-08 22:00 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-05-08 22:18 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-05-08 18:12 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-05-09 07:04 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Ian Collins <ian-news@hotmail.com> - 2017-05-10 07:50 +1200
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-05-09 13:31 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Ian Collins <ian-news@hotmail.com> - 2017-05-10 08:58 +1200
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-05-09 14:25 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Philip Lantz <prl@canterey.us> - 2017-05-18 05:45 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj scott@slp53.sl.home (Scott Lurndal) - 2017-05-18 14:02 +0000
                Re: https://github.com/bartg/langs/tree/master/bccproj David Brown <david.brown@hesbynett.no> - 2017-05-10 14:32 +0200
                Re: https://github.com/bartg/langs/tree/master/bccproj raltbos@xs4all.nl (Richard Bos) - 2017-05-10 10:19 +0000
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-05-10 09:51 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj scott@slp53.sl.home (Scott Lurndal) - 2017-05-10 17:37 +0000
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-05-10 10:53 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Tim Rentsch <txr@alumni.caltech.edu> - 2017-05-14 12:39 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-05-15 07:58 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Keith Thompson <kst-u@mib.org> - 2017-05-15 11:54 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-05-15 12:25 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Keith Thompson <kst-u@mib.org> - 2017-05-15 15:20 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-05-15 15:43 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Tim Rentsch <txr@alumni.caltech.edu> - 2017-05-16 04:38 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-05-16 12:48 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj raltbos@xs4all.nl (Richard Bos) - 2017-05-15 12:34 +0000
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-05-15 08:02 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-08 18:24 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-05-10 05:32 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Thiago Adams <thiago.adams@gmail.com> - 2017-05-06 12:04 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-04-28 09:53 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj David Brown <david.brown@hesbynett.no> - 2017-04-28 19:47 +0200
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-04-28 11:56 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Keith Thompson <kst-u@mib.org> - 2017-04-28 12:21 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-04-28 13:07 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj David Brown <david.brown@hesbynett.no> - 2017-04-28 22:23 +0200
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-04-28 14:03 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Keith Thompson <kst-u@mib.org> - 2017-04-28 14:57 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-04-28 15:57 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Keith Thompson <kst-u@mib.org> - 2017-04-28 11:49 -0700
            Re: https://github.com/bartg/langs/tree/master/bccproj jacobnavia <jacob@jacob.remcomp.fr> - 2017-04-26 13:31 +0200
              Re: https://github.com/bartg/langs/tree/master/bccproj GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-04-26 15:14 +0200
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-04-26 15:10 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-04-26 16:36 +0200
                Re: https://github.com/bartg/langs/tree/master/bccproj Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-04-26 08:49 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj David Brown <david.brown@hesbynett.no> - 2017-04-26 20:44 +0200
                Re: https://github.com/bartg/langs/tree/master/bccproj GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-04-26 21:02 +0200
                Re: https://github.com/bartg/langs/tree/master/bccproj David Brown <david.brown@hesbynett.no> - 2017-04-26 22:07 +0200
                Re: https://github.com/bartg/langs/tree/master/bccproj GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-04-26 22:56 +0200
                Re: https://github.com/bartg/langs/tree/master/bccproj David Brown <david.brown@hesbynett.no> - 2017-04-27 11:16 +0200
                Re: https://github.com/bartg/langs/tree/master/bccproj Richard Heathfield <rjh@cpax.org.uk> - 2017-04-27 10:53 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj David Brown <david.brown@hesbynett.no> - 2017-04-27 12:56 +0200
                Re: https://github.com/bartg/langs/tree/master/bccproj "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-04-27 04:13 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj bartc <bc@freeuk.com> - 2017-04-27 12:27 +0100
                Re: https://github.com/bartg/langs/tree/master/bccproj "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-04-27 06:05 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Ian Collins <ian-news@hotmail.com> - 2017-04-27 09:38 +1200
                Re: https://github.com/bartg/langs/tree/master/bccproj David Kleinecke <dkleinecke@gmail.com> - 2017-04-26 17:40 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Geoff <geoff@invalid.invalid> - 2017-04-26 22:22 -0700
                Re: https://github.com/bartg/langs/tree/master/bccproj Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-04-27 01:45 -0700
        Re: https://github.com/bartg/langs/tree/master/bccproj Geoff <geoff@invalid.invalid> - 2017-04-26 21:55 -0700
          Re: https://github.com/bartg/langs/tree/master/bccproj David Brown <david.brown@hesbynett.no> - 2017-04-27 11:25 +0200
            Re: https://github.com/bartg/langs/tree/master/bccproj "James R. Kuyper" <jameskuyper@verizon.net> - 2017-04-27 12:59 -0400
          Re: https://github.com/bartg/langs/tree/master/bccproj GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-04-27 15:03 +0200
            Re: https://github.com/bartg/langs/tree/master/bccproj scott@slp53.sl.home (Scott Lurndal) - 2017-04-27 13:27 +0000
      Re: https://github.com/bartg/langs/tree/master/bccproj GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-04-26 01:29 +0200
      Re: https://github.com/bartg/langs/tree/master/bccproj Philip Lantz <prl@canterey.us> - 2017-04-26 10:14 -0700
        Re: https://github.com/bartg/langs/tree/master/bccproj supercat@casperkitty.com - 2017-04-26 12:25 -0700
  Re: https://github.com/bartg/langs/tree/master/bccproj Keith Thompson <kst-u@mib.org> - 2017-04-24 15:26 -0700
  Re: https://github.com/bartg/langs/tree/master/bccproj jacobnavia <jacob@jacob.remcomp.fr> - 2017-04-26 11:36 +0200

csiph-web