Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Unexpected and difficult to understand SIGSEGV Date: Sat, 03 Oct 2015 19:13:40 -0700 Organization: None to speak of Lines: 42 Message-ID: References: <8362e3dd-17c5-4d88-a88f-5116ea0f10e0@googlegroups.com> <9256d7fa-5b3e-4183-b071-d910254623ce@googlegroups.com> <2da82a81-43ee-49eb-9357-6a7e06cfac03@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="1289"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ayvPj/MlNbGRdO8eAo47H" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:luHm1V3MQsSn4/KAmzJ0seY/oTI= sha1:PLRTJ+JsLmIdB3Fdpj5598+pLyo= Xref: csiph.com comp.lang.c:71770 supercat@casperkitty.com writes: > On Saturday, October 3, 2015 at 5:52:10 PM UTC-5, James Kuyper wrote: >> There is no such requirement. > > What exactly would the Standard specify given: > > int main(void) > { > int32_t x=-65537; > int16_t y=x; > printf("%ld\n",(long)y); > return 0; > } Since the value of x is outside the range of int16_t, the implicit conversion yields an implementation-defined result or raises an implementation-defined signal. > Would it be legitimate for an implementation to raise an implementation- > defined signal or use some implementation-defined method of conversion > that yields a value other than -1? Certainly. (The common implementation of 2's-complement arithmetic has wraparound semantics, but the standard says nothing about that.) > The Standard clearly implies that > a legitimate implementation must supply documentation sufficient to > ascertain what the above code would do on that implementation, and > most implementations would certainly yield -1, but the fact that an > int16_t is required to use a two's-complement representation would not > in and of itself preclude the possibility of an implementation defining > some other means of doing the conversion (e.g. saturating to -32767 or > -32768). Correct. -- 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"