Re: how to make gcc warn about arithmetic signed overflow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux