C PSA/periodic reminder: YOU CANNOT CALL A VARIADIC FUNCTION VIA AN EXPRESSION OF NON-VARIADIC FUNCTION TYPE MATCHING THE ARGS YOU WANT TO USE, OR VICE VERSA!
Conversation
Replying to
By casting a function pointer? I'd never even thought to try it, but now that you mention it, I certainly wouldn't expect it to work, though it might by accident on ancient systems that always pass args on stack.
1
Replying to
That, or by a declaration in one translation unit mismatching the definition in another.
2
Unfortunately Clang / GCC don't have a way to find these bugs unless it's done via a function pointer.
No, because C type information is lost compiling to bytecode. There's no error even with a more egregious violation. Needs a compile-time sanitizer.
% cat a.c
int foo(void) {
return 1;
}
% cat b.c
void foo(int x);
void bar() {
foo(5);
}
% clang a.c b.c -flto -shared
2
Show replies


