J
Jef Driesen
Hi,
Sorry for cross-posting to c.l.c and c.l.c++, but I would like to know
the answer in both C and C++.
I know it is possible to initialize a character array with a string literal:
char str[] = "hello";
which is often more convenient than having to write:
char str[] = {'h', 'e', 'l', 'l', 'o', 0};
But in my case the array is not a real string but a byte array. Hence I
don't want the terminating null character, and I use unsigned char for
the data type. Now, s it allowed to write this:
unsigned char str[5] = "hello";
It works fine with gcc (in C code), but with msvc (in C++ code) I get an
error "C2117: array bounds overflow".
So I wonder if this construct is allowed, and whether there is a
difference in C and C++.
Thanks,
Jef
Sorry for cross-posting to c.l.c and c.l.c++, but I would like to know
the answer in both C and C++.
I know it is possible to initialize a character array with a string literal:
char str[] = "hello";
which is often more convenient than having to write:
char str[] = {'h', 'e', 'l', 'l', 'o', 0};
But in my case the array is not a real string but a byte array. Hence I
don't want the terminating null character, and I use unsigned char for
the data type. Now, s it allowed to write this:
unsigned char str[5] = "hello";
It works fine with gcc (in C code), but with msvc (in C++ code) I get an
error "C2117: array bounds overflow".
So I wonder if this construct is allowed, and whether there is a
difference in C and C++.
Thanks,
Jef