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


Groups > comp.lang.c > #21892

Re: Why no warning?

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: Why no warning?
Date 2012-06-06 06:29 -0400
Organization A noiseless patient Spider
Message-ID <jqnbdf$48b$1@dont-email.me> (permalink)
References <6d2a019d-fea9-406d-9cda-e0d77566f4e6@googlegroups.com> <jqn9uq$rrh$1@dont-email.me> <d5b828df-5a09-4515-92ee-b89350ee48d1@googlegroups.com>

Show all headers | View raw


On 06/06/2012 06:17 AM, Hill Pang wrote:
> On Wednesday, June 6, 2012 6:04:09 PM UTC+8, Noob wrote:
>> Hill Pang wrote:
>>
>>> I was expecting a warning for this assignment, but can't get from GCC, why?
>>> isn't it an overflow?
>>>  
>>> char c = 0xff;
>>
>> 1) consider the gcc options -fsigned-char and -funsigned-char
>> and ask yourself: "is char a signed or unsigned type?"
>>
>> 2) consider the gcc option -Wstrict-overflow=n
>> (-Wall enables -Wstrict-overflow=1)
>> Note however that "overflow" only makes sense in the context
>> of signed arithmetic, since the language properly defines the
>> "wrap-around" semantics for unsigned arithmetic.
> 
> 1) I am running the GCC on X86, I am sure by default the char should be signed, and even I add the option -fsigned-char, the result is same.
> 2) I tried -Wall and -Wstrict-overflow=1, no luck to get the warning.

You need the -pedantic option:

gcc -pedantic -c overchar.c
overchar.c:1: warning: overflow in implicit constant conversion
-- 
James Kuyper

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


Thread

Why no warning? Hill Pang <pangbw@gmail.com> - 2012-06-06 02:42 -0700
  Re: Why no warning? Noob <root@127.0.0.1> - 2012-06-06 12:04 +0200
    Re: Why no warning? Hill Pang <pangbw@gmail.com> - 2012-06-06 03:17 -0700
      Re: Why no warning? James Kuyper <jameskuyper@verizon.net> - 2012-06-06 06:29 -0400
        Re: Why no warning? Noob <root@127.0.0.1> - 2012-06-06 12:54 +0200
  Re: Why no warning? David Brown <david@westcontrol.removethisbit.com> - 2012-06-06 12:28 +0200
    Re: Why no warning? Noob <root@127.0.0.1> - 2012-06-06 12:55 +0200
      Re: Why no warning? David Brown <david@westcontrol.removethisbit.com> - 2012-06-06 13:17 +0200
  Re: Why no warning? Hill Pang <pangbw@gmail.com> - 2012-06-06 04:35 -0700
    Re: Why no warning? James Kuyper <jameskuyper@verizon.net> - 2012-06-06 08:56 -0400
      Re: Why no warning? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-06-07 15:05 +0000
  Re: Why no warning? China Blue Max <chine.bleu@yahoo.com> - 2012-06-06 04:53 -0700
    Re: Why no warning? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-06 13:29 +0100
      Re: Why no warning? Willem <willem@toad.stack.nl> - 2012-06-06 13:07 +0000
        Re: Why no warning? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-06 17:37 +0100
  Re: Why no warning? Ralph Spitzner <rasp@spitzner.org> - 2012-06-06 16:57 +0200
    Re: Why no warning? James Kuyper <jameskuyper@verizon.net> - 2012-06-06 11:20 -0400
    Re: Why no warning? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-06 17:45 +0100

csiph-web