This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Preprocessor keyword #echo is missing
- From: Martin Sebor <sebor at roguewave dot com>
- To: Zack Weinberg <zack at codesourcery dot com>
- Cc: "J. Grant" <jg-web at jguk dot org>, Falk Hueffner<falk dot hueffner at student dot uni-tuebingen dot de>, gcc-bugs<gcc-bugs at gcc dot gnu dot org>
- Date: Tue, 11 Feb 2003 12:42:49 -0700
- Subject: Re: Preprocessor keyword #echo is missing
- Organization: Rogue Wave Software, Inc.
- References: <3E301211.7090405@gmx.net> <87bs2725gs.fsf@student.uni-tuebingen.de> <3E308BD8.40401@gmx.net> <878yxbqs6j.fsf@egil.codesourcery.com> <3E30976B.7030506@gmx.net> <873cnjqq63.fsf@egil.codesourcery.com> <3E37E3F5.4060709@jguk.org> <87fzquwupv.fsf@egil.codesourcery.com> <3E494030.90803@roguewave.com> <877kc6wrex.fsf@egil.codesourcery.com>
Zack Weinberg wrote:
Martin Sebor <sebor@roguewave.com> writes:
A #echo at the compiler level rather than at the preprocessor level
would, IMHO, be extremely useful in the context of metaprogramming.
At the very least, it would provide a framework for the proposed
implementation of the static assert feature:
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2002/n1381.htm
That is an #error analog, not #echo. I do consider it a useful
feature, but if I were implementing it I'd just take the spec straight
from N1381 (with appropriate modifications for C) -- don't see the
need for a static_echo().
Yes, static_assert is equivalent to a #error. I was suggesting
a more ambitious facility, one that would subsume static_assert,
i.e., one that could (but wouldn't be limited to) halt compilation
based on a compile-time predicate, but that could also print
text messages during compilation.
E.g., something along these (half baked) lines
template <int N>
struct factorial {
enum { value = N * factorial<N - 1> };
};
template <>
struct factorial<0> { enum { value = 1 }; };
template <int N>
struct print_int {
#echo "the value is %d", N
};
template struct print_int<factorial<7>::value>;
I wonder why the string literal is included there, when it isn't for
the runtime assert().
To issue more meaningful and better readable diagnostics
that would be possible otherwise. The libstdc++ concept
checking facility is a good example of how hard to read
the diagnostics can be and how much effort it takes to
make them at least somewhat comprehensible.
Regards
Martin