view lib/verify.h @ 6282:ad1b37bff099

Fix typo in comment.
author Paul Eggert <eggert@cs.ucla.edu>
date Fri, 23 Sep 2005 17:52:49 +0000
parents 7ca9a453289e
children b8c8dc112e16
line wrap: on
line source

/* Compile-time assert-like macros.

   Copyright (C) 2005 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */

/* Written by Paul Eggert and Jim Meyering.  */

#ifndef VERIFY_H
# define VERIFY_H 1

/* Each of these macros verifies that its argument R is a nonzero
   constant expression.  To be portable, R's type must be integer (or
   boolean).  Unlike assert, there is no run-time overhead.  */

/* A type that is valid if and only if R is a nonzero constant expression.
   The symbols verify_type__ and verify_error_if_negative_size__ are
   private to this header file.  */

# define verify_type__(R) \
    struct { int verify_error_if_negative_size__ : (R) ? 1 : -1; }

/* Verify requirement R at compile-time, as a declaration.  */

# define verify(R) \
    extern int (* verify_function__ (void)) [sizeof (verify_type__ (R))]

/* Verify requirement R at compile-time, as an expression.
   This macro can be used in some contexts where verify cannot, and vice versa.
   Return void.  */

# define verify_expr(R) ((void) ((verify_type__ (R) *) 0))

#endif