[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Refreshed genx.h, plus some plans

  • To: xml-dev@l...
  • Subject: Re: Refreshed genx.h, plus some plans
  • From: David Tolpin <dvd@d...>
  • Date: Sun, 25 Jan 2004 12:54:12 +0400 (AMT)

iso c.pdf
> > So Joe's claim looks exactly right: passing a const char array to a
> I'm convinced. It was me who didn't know how it worked; actually, I did

Explanations. 

- 6.5.16.1 of ISO C says that assignments between pointers require that all
  pointed to type qualifiers on the right side must be present on the left side
  of assignment.

- I have an old printout of something which is (I think) ANSI C Standard (1989),
  which, in 3.3.16, does not impose this restriction. I have just purchased the 
  ISO C (PDF version) and have made sure that this restriction does indeed
  exist.

- There is a note from Dennis Ritchie to X3J11

  http://www.lysator.liu.se/c/dmr-on-noalias.html

  . In the concluding part of this note, Ritchie proposes to

: 2. Rewrite the constraint on page 54, lines 14-15, to say that pointers may be
: assigned without taking qualifiers into account.

...

: 4. String literals have type  `const char []'.

and the note at the top of the page says:

: [After Dennis Ritchie had written the following critique of type qualifiers in
: the draft ANSI standard of January 1988, the bar on assignments to previously
: const-qualified lvalues was removed, and noalias did go.]

which is not true for the ISO C standard.

The latter, the fact that strings are immutable but not 'const char []', is
justified by compatibility issues, but it also means that this restriction
cannot be checked at compile time; passing a constant string to a subroutine
which will try to modify it will only be detected at run-time; gnu C compiler
will generate the code which yields bus error on many architectures.

The only use of 'const' in 'const char *s' is to inform the user of the
interface that the function will not modify his data. The user may choose 
to rely on it; but nothing in the language assures that this information 
is right. And while 'const' modifier provides false confidence for users
of the interface, it in fact does not check for anything. It only misleads.

The only reason to have pointers to constant data at all is to have a pointer
to constant assigned a pointer to a mutable and then pass that pointer somewhere
where only 'const' pointers are accepted. But, inside of that black box, that
can be modified again, and no one will notice.

'const' is a well-intended line noise, in my opinion; as any line noise, 
it makes recognizing the signal a harder job.

David Tolpin

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.