This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: how to make gcc warn about arithmetic signed overflow


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>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]