[cmake-developers] CheckSymbolExists.cmake

Christopher Sean Morrison brlcad at mac.com
Wed Jun 5 17:33:28 EDT 2013



On Jun 05, 2013, at 04:10 PM, Brad King <brad.king at kitware.com> wrote:

On 06/05/2013 03:16 PM, Christopher Sean Morrison wrote:
> getting past GCC's pedantic point about direct type conversion.

If the user tests with -Werror that warning could be a problem,
so that flag is worth stripping if possible.

Unless like in our situation, Werror compilability is specifically what we are checking.

Ideally we need a test that works with gcc flags

-std=c99 -pedantic -Werror -O3

The only one I've found from some quick experiments requires
two source files:

[snip]

In this approach we hide the pointer conversion from the compiler.
If a compiler does whole-program optimization we could restore the
argc offset part.

Interesting.  I'd be surprised if hiding the conversion behind an incomplete function prototype is portable to other compilers.  Or if they turned on warnings about incomplete prototypes, it'll bark at that as well.  How about doing it an ol' fashioned way:

#include <stdio.h>
int main(void) {
  union t { void (*fn)(); char val[8]; } a = {0};
  a.fn = (void (*)())&printf;
  return (a.val[0] + a.val[1] + a.val[2] + a.val[3] + a.val[4] + a.val[5] + a.val[6] + a.val[7] == 0);
}

The conversion is fully masked, compliant, and cannot be optimized away.

Cheers!
Sean

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20130605/665a04ca/attachment.html>


More information about the cmake-developers mailing list