OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Refreshed genx.h, plus some plans

[ Lists Home | Date Index | Thread Index ]

> > 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




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS