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: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Sat, 21 Sep 2013 19:42:29 +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> <CAH6eHdTToM+TMy55m5HYo39DC8nA0RrTma1Bp5OnhUtPErMfOA at mail dot gmail dot com>
On Sat, Sep 21, 2013 at 06:24:13PM +0100, Jonathan Wakely wrote:
> On 21 September 2013 17:46, wrote:
> > Is it possible for gcc to produce a
> > warning in such situation?
>
> If ab and bc are 'const' then G++ will warn:
>
> o.cc: In function âint main()â:
> o.cc:5:14: warning: integer overflow in expression [-Woverflow]
> int r = ab * bc;
> ^
>
> The C compiler still doesn't warn though, due to different rules for
> how constants are handled between C and C++.
Hmm, I don't know too much about C++ but why would a C++ compiler
produce a warning only if two operands were const? I learned that in C
`const' modifier only means that I promise to the compiler that this
variable will be read-only, its value can be changed using pointers
but the result is undefined and that const != constant expression. So
are the differences in const between C and C++ so much complex or is
it just a compiler that decides to act this way? From what you said, I
believe the differnces are more complex than I thought.
Anyway, do you know how to make gcc warn about this in pure C?
--
<wempwer@gmail.com>