Sebastian Redl wrote: > Michel Van den Bergh wrote: >> That's strange. When I try to compile this with gcc 4.3.2 on Ubuntu >> 8.10 (Intel core2 duo) >> I get >> >> stest.c: In function ‘main’: >> stest.c:13: warning: format ‘%s’ expects type ‘char *’, but argument 2 >> has type ‘char[20]’ >> >> The resulting binary does not segfault but prints garbage (probably >> uninitialized data). >> >> g++ still works fine and does not give any warning, even when >> compiling with -Wall. > The C++ standard says in 5.2.2p7: "The lvalue-to-rvalue, > array-to-pointer, and function-to-pointer standard conversions are > performed on the argument expression." > > The C standard says no such thing;
It does, in 6.3.2.1. "Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type ‘‘array of type’’ is converted to an expression with type ‘‘pointer to type’’ that points to the initial element of the array object and is not an lvalue." Andrew.