C++0x to save the day
Posted Jun 18, 2008 22:28 UTC (Wed) by
pphaneuf (subscriber, #23480)
In reply to:
C++0x to save the day by ajross
Parent article:
Converting GCC to C++
This is because template parameters are untyped (they are types themselves!), and concepts are basically typing for types. C preprocessor macros have exactly the same problem. Consider this:
#include <stdio.h>
// Ignore that this is unsafe, it's just an example.
#define mymacro(X) printf(X)
void main() {
mymacro(42);
}
You can see that there is no typing for X there, and the same applies to template parameters (except they actually do have a little bit of typing, but not much).
Also, you might note that in C, this compiles with a warning, then crashes at runtime. In C++, compile-time error, because, well, it is. That's an example of what I was saying earlier: program in C, but call your file foo.cc instead of foo.c, and it will be better. You won't get any of those horrible template diagnostic messages (you don't use templates!), you'll in fact have better warnings and errors.
(
Log in to post comments)