Re:When static makes your C code 10 times faster
by not2b on Sunday July 04, 2021 @11:58AM
(#27730616)
This is why language standards specify what the compiler can assume and call out some behavior as undefined, exactly so compilers don't have to be paranoid and produce code that sucks. If an underlying object is const, the compiler is allowed to assume that it does not change (it is valid to cast away const on a pointer or reference, but not if the object itself was declared const).
[ Parent
| on HN ]
Re:When static makes your C code 10 times faster
by toast0 on Sunday July 04, 2021 @12:16PM
(#27730749)
> (it is valid to cast away const on a pointer or reference, but not if the object itself was declared const).
Isn't it valid to cast to non-const for a const, but only invalid to modify the const through the casted pointer?
Re:When static makes your C code 10 times faster
by why_only_15 on Sunday July 04, 2021 @05:21PM
(#27732717)
Interestingly GCC will still optimize the loop function even if you have code that modifies the modulus. https://godbolt.org/z/EE9PnrY7s
Re:When static makes your C code 10 times faster
by colonwqbang on Sunday July 04, 2021 @07:22PM
(#27733423)
That code is invalid, it would give a compiler warning and possibly a runtime exception.