how to make gcc warn about arithmetic signed overflow

wempwer@gmail.com wempwer@gmail.com
Sat Sep 21 21:07:00 GMT 2013


On Sat, Sep 21, 2013 at 10:52:22PM +0200, Jędrzej Dudkiewicz wrote:
> >> > I think I can but it may cause an undefined behavior:
> >>
> >> Note, that Jonathan wrote "in a valid program". Your program is not
> >> valid, as it contains undefined behaviour - you change const int via
> >> pointer to non-const int.
> >
> > Is p pointer in my code a pointer to non-const int? It points to bc
> > int memory address and bc is constant. Does C language bind constness
> > to an indentifier instead of memory address?
> 
> Yes. I don't know about your version of gcc, but with 4.8.1 I get:
> 
> [jd@megalodon ~]$ cat x.c
> int main() {
>         const int i = 10;
>         int* pc = &i;
>         *pc = 1;
>         return *pc;
> }
> 
> [jd@megalodon ~]$ gcc x.c -o x
> x.c: In function ‘main’:
> x.c:3:12: warning: initialization discards ‘const’ qualifier from
> pointer target type [enabled by default]
>   int* pc = &i;
> 
> Which means that pc doesn't inherit constness of pointed ...memory?
> value? I'm not sure how to call it.

Oh, my gcc shows me the same warning. Thank you for clarification.

-- 
<wempwer@gmail.com>



More information about the Gcc-help mailing list