On 9/28/25 02:56, Jussi Kivilinna wrote:
On 28/09/2025 04:33, Jacob Bachmeyer via Gcrypt-devel wrote:
[...]

Would this make sense as "const unsigned int sizeof_mat" to enable better compiler optimizations/inlining since PK_NROWS and nblocks_H seem to be constants?  Or is GCC able to deduce that sizeof_mat is only assigned once?

With GCC -O0, "unsigned int sizeof_mat" and "const unsigned int sizeof_mat" generate the same code, value is assigned to stack memory. With -O1 and above, compiler deduces that this is constant variable and optimizes as it sees best fit. 'const' on stack variables only really affects syntax checks and gives compile-time error when trying reassigning to that variable.

So GCC does recognize constants and optimize accordingly.  Good. Why not include the "const" as well to ensure that a compile-time error will be thrown if any future code attempts to change the value, since there is no way that such code could be correct?


-- Jacob



_______________________________________________
Gcrypt-devel mailing list
[email protected]
https://lists.gnupg.org/mailman/listinfo/gcrypt-devel

Reply via email to