This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: how to make gcc warn about arithmetic signed overflow
- From: wempwer at gmail dot com
- To: Brian Drummond <brian at shapes dot demon dot co dot uk>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sat, 21 Sep 2013 19:46:14 +0200
- Subject: Re: how to make gcc warn about arithmetic signed overflow
- Authentication-results: sourceware.org; auth=none
- References: <20130921164609 dot GC3086 at a dot lan> <1379785029 dot 2477 dot 8 dot camel at Gannet dot Four>
On Sat, Sep 21, 2013 at 06:37:09PM +0100, Brian Drummond wrote:
> On Sat, 2013-09-21 at 18:46 +0200, wempwer@gmail.com wrote:
> > int ab = 50000;
> > int bc = 50000;
> > int r = ab * bc;
> >
> > Is it possible for gcc to produce a
> > warning in such situation?
>
> Yes, gcc the Gnu Compiler Collection can produce such a warning:
>
> procedure test_ovf is
> ab : integer := 50000;
> bc : integer := 50000;
> r : integer := ab * bc;
> begin
> null;
> end test_ovf;
>
> gcc -c test_ovf.adb
> test_ovf.adb:4:22: warning: value not in range of type
> "Standard.Integer"
> test_ovf.adb:4:22: warning: "Constraint_Error" will be raised at run
> time
> However I'm not sure it is allowed to do the same with C.
Wow, what's the language you use here? It looks like some kind of
Pascal.
Sorry guys for not being 100% clear in this question - I am only
interested in C language.
--
<wempwer@gmail.com>