On Sat, Sep 21, 2013 at 07:30:02PM +0100, Jonathan Wakely wrote: > On 21 September 2013 18:42, <wempwer@xxxxxxxxx> wrote: > > > > 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, > > So the compiler knows that the values of ab and bc, because they must > always have the values they were initialized with. > > If the compiler was smarter it would be able to also warn for > non-const values if it can prove that nothing has modified the > variables since they were initialized. > > > its value can be changed using pointers > > No, that's not true. You can't change the value of a const object in a > valid program. > > > but the result is undefined and that const != constant expression. I think I can but it may cause an undefined behavior: const int bc = 50000; int *p = &bc; *p = 10; printf("Modified const: %d\n", bc); 10 will be printed. -- <wempwer@xxxxxxxxx>