I have a struct with an unsigned char[16] field that I'd like to initialize to zeros. The following (strongly simplified) code compiles fine with clang (OS X):
struct GUID {
unsigned char bytes[16];
GUID() : bytes("\0\0\0\0""\0\0\0\0""\0\0\0\0""\0\0\0") {};
}
Note I use 15 \0s because the 16th is the zero terminator of the string literal, and clang complains if you initialize a string with too many bytes.
Now, when I try to compile with GCC 4.5.3 (cygwin), I get:
error: incompatible types in assignment of 'const char [16]' to 'unsigned char [16]'
Why doesn't it work, and how can I make it work? (I could obviously loop through the array in the constructor, but I'd like to use the initialization list if possible, and I'd like to understand why it works in one compiler, but not the other.)