[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: proposal: lib/verify.h

From: Paul Eggert
Subject: Re: proposal: lib/verify.h
Date: Thu, 30 Jun 2005 15:41:56 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Jim Meyering <address@hidden> 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]; }))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]