TITLE: Sizeof and string literals PROBLEM: jeffery@flood.com (Jeffery Cavallaro) I have been actively working the examples in the Lippman primer with my BC++ 3.1 compiler. I have found two things that I believe are bugs: 1. Character array initialization char[11] = "fundamental"; This fragment succeeds (even though there is no room for the terminator). The sizeof operator correctly reports a size of 12 though. 2. Sizeof cannot make up its mind when determining the size of reference types. For predefined types, I get the size of the pointer. For "instances" of class templates I get the object size. For class template "types" I get pointer size. RESPONSE: steve@taumet.com (Steve Clamage), 28 Nov 92 Vice Chair, ANSI C++ Committee, X3J16 1. Let's first make the example syntactically legal, since what you show should not be accepted by the compiler at all. char s[11] = "fundamental"; The rules for this example are different in C and in C++. In C, the initialization is legal, and results in the 11 characters of "fundamental" stored in array 's', with no terminating null. In C++, the initialization is NOT legal, since there is no room for the trailing null, and the compiler should report an error. If the compiler accepts this in C++ mode, it is a compiler bug. You don't say what you are taking the size of. The size of 's' should be 11, not 12, since that is the way it is declared. The size of the string literal should be 12, the 11 characters plus a trailing null. If the compiler reports sizeof(s) as 12, that is a compiler bug. (The point is moot if the compiler decalred the program in error.) 2. This is too vague to evaluate. The sizeof operator is supposed to return the size of the referenced object (ARM 5.3.2). If it returns something else, it sounds like a compiler bug.