C String Literal "too big for character"
c, literals, string
Solution
Unfortunately you've stumbled upon the fact that `\x` will read every last character that appears to be hex1,2, instead you'll need to break this up:
const char *x = "\xBC" "d"; /* const added to satisfy literal assignment probs */
Consider the output from this program:
/* wide.c */
#include <stdio.h>
int main(int argc, char **argv)
{
const char *x = "\x000000000000021";
return printf("%s\n", x);
}
Compiled and executed:
C:\temp>cl /nologo wide.c
wide.c
C:\temp>wide
!
- Tested on Microsoft's C++ compiler shipped with VS 2k12, 2k10, 2k8, and 2k5
- Tested on gcc 4.3.4.
Problem
With MSVC 2010 i try to compile this in C or C++ mode (needs to be compilable in both) and it does not work. Why? I thought and found in the documentation that '\x' takes the next two characters as hex characters and not more (4 characters when using \X"). I also learned that there is no portable way to use character codes outside ASCII in C source code anyway, so how can i specify some german ISO-8859-1 characters? ``` int main() { char* x = "\xBCd"; // Why is this not char(188) + 'd' } // returns test.c(2) : error C2022: '3021' : too big for character // and a warning with GCC ```