This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PATCH: Pascal Strings -- TAKE FOUR


On 04-Jul-2001, Richard Earnshaw <rearnsha@arm.com> wrote:
> + Pascal-style literals are treated by the compiler as being of type
> + @samp{const unsigned char []} in C++ and @samp{unsigned char []} (or
> + @samp{const unsigned char []}, if the @w{@option{-Wwrite-strings}}
> + option is given) in C.  
> 
> Yes, this is what -Wwrite-strings does (in a way), but is this really 
> correct? 

Yes, it's correct.  But the documentation here could potentially be made
clearer.

> String literals in 
> (GNU) C are really constants unless -fwritable-strings is given.

Without -Wwrite-strings, string literals have type "char []",
"unsigned char []", or "wchar_t[]", depending on what kind of
string literal it is.  This type is not const.  But nevertheless, the
values are by default not modifiable.  Any attempt to do so will
result in undefined behaviour at runtime, unless -fwritable-strings is
given.

So what the documentation above says about the type is correct.
But it might be helpful to say something about the modifiability too.
E.g. perhaps we could append the following?
	
	In all other respects, Pascal-style string literals behave the
	same as ordinary string literals.  For example, if a program
	attempts to modify the conents of a Pascal-style string literal
	at run-time, the behaviour is undefined, unless the
	-fwritable-strings option is used.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]