Re: how to make gcc warn about arithmetic signed overflow

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

 



>> > 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.
-- 
Jędrzej Dudkiewicz

I really hate this damn machine, I wish that they would sell it.
It never does just what I want, but only what I tell it.





[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