Jim Meyering <[EMAIL PROTECTED]> writes:

>   #define GL_CONCAT...
>   #define VERIFY(assertion) \
>     struct GL_CONCAT (compile_time_assert_, __LINE__) \
>       { char a[(assertion) ? 1 : -1]; }

This trick won't work if VERIFY is used in two different files with
the same line number.  Typically the problem would occur if there are
multiple headers that use VERIFY, or a header and a source file that
both use VERIFY.

Admittedly it's a bit of a pain to have to come up with a name for
each requirement, as is the case with mktime.c now.

So, how about if we simply dump the named-requirement variant, and
stick only with the unnamed variant?  If there is a need to verify
stuff at the top level, we can do something like this:

static inline void
verify_mktime_requirements (void)
{
  verify (TYPE_IS_INTEGER (time_t));
  verify (TYPE_TWOS_COMPLEMENT (int));
  ...
}

(The "inline" is to pacify GCC so that it doesn't warn about the
unused function.)

One other thought: "assert" uses lower-case letters, and I'd
like "verify" to do so too.

So, how about the following macro instead?

/* Verify REQUIREMENT at compile-time, as an expression.
   Unlike assert, there is no run-time overhead.
   Return void.  */
#define verify(requirement) \
  ((void) sizeof (struct { char a[(requirement) ? 1 : -1]; }))


_______________________________________________
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib

Reply via email to