by Michael S. Kaplan, published on 2006/04/21 03:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/04/21/580316.aspx
The compiler error is C4428: universal-character-name encountered in source. The description of it in MSDN has a few problems in regard to understandability:
Visual C++ Concepts: Building a C/C++ Program
Compiler Warning (level 4) C4428Error Message
universal-character-name encountered in sourceThe compiler issues C4428 when it detects at least one universal character name in a source code file. To fix this warning, use the Unicode equivalent of the universal character name.This warning is only issued once per compiland.The following sample generates C4428:
// C4428.cpp
// compile with: /W4 /c
int \u20ac = 0; // C4428 universal character name
/// The following line is the Unicode equivalent of \u20ac:
// int = 0;
Now we'll start with the code sample that won't compile -- obviously they meant put "// int € = 0;" but there is no character there -- it is just a space.
And of course there is the unclear error message -- 'universal-character-name encountered in source' -- as if including a Unicode UTF-16 code unit in source has anything whatsoever to do with character names in either Unicode or ISO 10616.
Moving deeper, a currency symbol like the Euro is a symbol (just like the space, as I pointed out here) so if using a random Unicode character with a Unicode General Category of Sc (Symbol, Currency) is a valid variable name then that is just poor compiler design (and not conformant with the current design for identifiers being considered by the C/C++ committees). Plus if you look at the current rules for identifiers in Microsoft C/C++:
identifier:
nondigitidentifier nondigitidentifier digitnondigit: one of
_ a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Zdigit: one of
0 1 2 3 4 5 6 7 8 9
So unless I am missing something you can't have U+20ac as a variable name anyway right now in C or C++....
Ok, moving past the terrible example (broken on the levels of both saying the wrong thing and saying it poorly), there is having this warning at all.
Why is the \u syntax worthy of level 4 warning? It is actually something perfectly acceptable to do, and unless you are a native speaker of a language it is a hell of a lot more useful than putting random characters into source code.
I have a colleague who made a huge push to get our piece of the Windows project compiling with /w4 and I'd feel like that kind of a push was a lot 'symbolically' more useful if the compiler stuck with the warnings that had a real purpose.
This one is only slightly more useful than a warning for identifiers with an odd number of characters in it!
Anyway, do not feel badly about supressing this warning -- it is begging for supression, truly.
This post brought to you by "€" (U+20ac, a.k.a. EURO SIGN)
# Andrew West on 21 Apr 2006 5:35 AM:
# Michael S. Kaplan on 21 Apr 2006 8:58 AM:
# Maurits [MSFT] on 21 Apr 2006 11:31 AM:
# Maurits [MSFT] on 21 Apr 2006 11:34 AM:
# Maurits [MSFT] on 21 Apr 2006 11:58 AM:
# Maurits [MSFT] on 21 Apr 2006 12:12 PM:
# Mihai on 21 Apr 2006 12:46 PM:
# Maurits [MSFT] on 21 Apr 2006 1:54 PM:
# Michael S. Kaplan on 21 Apr 2006 2:06 PM:
# Maurits [MSFT] on 21 Apr 2006 2:15 PM:
# Michael Dunn_ on 21 Apr 2006 5:16 PM:
# Maurits [MSFT] on 21 Apr 2006 5:29 PM:
# Mike Dimmick on 21 Apr 2006 7:02 PM:
# Maurits [MSFT] on 21 Apr 2006 7:51 PM:
# josh on 22 Apr 2006 12:41 AM: