On 06/05/2013 05:33 PM, Christopher Sean Morrison wrote:
> union t { void (*fn)(); char val[8]; } a = {0};
> a.fn = (void (*)())&printf;
Yes, if we know the symbol is a function, but it could be data too.
That's why the name "CheckSymbolExists" was chosen to replace the
original "CheckFunctionExists".
We can return to hiding sending the pointer through varargs
but move the symbol definition to somewhere the compiler will
not optimize it out:
$ cat symbol_main.c
#include <stdio.h> /* declares tested symbol */
extern int cmakeRequireSymbol(int, ...);
int main(int argc, const char* argv[]) { return cmakeRequireSymbol(argc,
&printf); }
$ cat symbol_impl.c
int cmakeRequireSymbol(int x, ...) { return x; }
$ gcc -std=c99 -pedantic -Werror -O3 symbol_main.c symbol_impl.c
Alternatively we could go back to your suggestion to cast through
an integer type but use a few #ifdef's to try to choose an integer
type large enough for the pointer (long, long long, or __int64).
-Brad
--
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers