Re: sscanf problem
Re: sscanf problem
- Subject: Re: sscanf problem
- From: Sailor Quasar <email@hidden>
- Date: Fri, 30 Jan 2004 15:32:58 -0500
On Friday, January 30, 2004, at 03:15 PM, lbland wrote:
here is a paragraph from a book I have that explains it:
"Traditionally - at least under UNIX - string constants are placed in
read/write storage and no two string constants are ever represented by
the same block of storage, even when they contain the same characters.
We consider it a bad programming style to modify the contents of a
string constant or to depend on distinct copies in storage, and Draft
Proposed ANSI C agrees by allowing strings to share storage and to be
in read-only memory. However, it is known that some UNIX library
routines do modify their string arguments, which are often string
constants. When a pointer to a writable string must be used, it is
better to initialize an array of characters than to establish a
pointer to a string constant."
In my opinion, it is good programming style to treat string constants
as always typed "const char * const", and to be const correct with
string pointers whenever possible, to help the compiler catch
accidental writes to memory that shouldn't be modified. Of course, it
still behooves the programmer to not cast const-ness away where it's
not absolutely necessary. Unfortunately, the UNIX system calls are not
known for being entirely const-correct, and the modification in-place
of input parameters is an artifact of older times when it was better to
write to existing memory rather than using more.
-- Sailor Quasar, High Codemaster of the Web, scourge of systems
MacOS is to Windows as Terminus is to Trantor.
Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.