On Sat, 2014-12-06 at 22:01 +0100, Niels Möller wrote:
Nikos Mavrogiannopoulos nmav@gnutls.org writes:
In modern compilers you cannot rely on that. The constructions if(0){} and other impossible situations are optimized out early.
Examples? I would expect any serious C compiler to do basic type checking of dead code (even if I don't expect to get all warnings generated by optimization passes, i.e., the warnings you normally get only if you compile with -O). If gcc stopped doing type checking on dead code, I would likely file a bug report.
An example that would compile and run perfectly on modern gcc is: #include <stdio.h> int main() { if (0) { call_this_unknown_function(); } else { printf("hello\n"); } }
but indeed, while it skips undefined functions, it still performs type checking on the known ones.
What do you suggest to do with the nettle macros? They are intended for use with the various _CTX() macros, and for that purpose, I think the current definitions with casts and all are adequate, so I'd prefer to not simply delete the cast.
What is the purpose of the cast? Isn't the macro supposed to have a function pointer input? If yes, I don't see the cast purpose, while I see the issues that it can cause. Yes I could have used the function, but I did use the macro which was part of the API, and should be treated as such.
Question is, does that solve a real problem?
What do you mean by that? I sent a real issue on the previous mail. A problem that would have been very hard to notice and debug. When the API and ABI are changed it is best to let the compiler warn of these changes and not hide them under casts.
regards, Nikos