proposal: lib/verify.h

2005-06-29 Thread Jim Meyering
[to make a long story short, skip down to the `I propose...' part near the end. ] Yesterday I did this in coreutils * src/pr.c (main, store_char): Use x2realloc on 1-byte base types, not x2nrealloc. The former is a little more concise and readable. N.B. this sort of tran

Re: proposal: lib/verify.h

2005-06-30 Thread Paul Eggert
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. Typicall

Re: proposal: lib/verify.h

2005-06-30 Thread Jim Meyering
Paul Eggert <[EMAIL PROTECTED]> wrote: > 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 dif

Re: proposal: lib/verify.h

2005-07-04 Thread Jim Meyering
FYI, I've just added this new file as lib/verify.h in coreutils. /* 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 b

Re: proposal: lib/verify.h

2005-07-04 Thread Paul Eggert
Jim Meyering <[EMAIL PROTECTED]> writes: >The implementation uses a struct declaration whose name includes the >expansion of __LINE__, so there is a small chance that two uses of >verify_decl from different files will end up colliding I thought about this problem for a bit and came up

Re: proposal: lib/verify.h

2005-07-05 Thread Jim Meyering
Paul Eggert <[EMAIL PROTECTED]> wrote: ... > How about if we just define GL_CONCAT0 etc. unconditionally? That's > what other .h files do. Similarly, we shouldn't need to "#undef > verify". > > I installed this patch into coreutils. Comments? Thanks. I like it. I agree that the declaration-bas

Re: [bug-gnulib] Re: proposal: lib/verify.h

2005-07-11 Thread Bruno Haible
Paul Eggert wrote: > ! # define verify_expr(R) ((void) sizeof (verify_type__ (R))) This doesn't work in C++: gcc gives an error "error: ISO C++ forbids defining types within sizeof" However, Jim's first version with the NULL pointer works in C++ too: #define verify_expr(R) (void) ((verify_type__

Re: [bug-gnulib] Re: proposal: lib/verify.h

2005-07-11 Thread Paul Eggert
Bruno Haible <[EMAIL PROTECTED]> writes: > However, Jim's first version with the NULL pointer works in C++ too: > > #define verify_expr(R) (void) ((verify_type__ (R) *) 0) > > I'd therefore suggest to use this one. Thanks for catching that; I followed your suggestion in coreutils. 2005-07-11 Pa