🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #50808

Re: Bug in C standard

#50808
From: Joe Buck
Date: Mon, 02 Aug 1993 20:58
54 lines
3185 bytes
rfg@netcom.com (Ronald F. Guilmette), responding to a different question
than the one that was actually asked, writes:
>Right.  GCC is correctly following the ANSI C standard.  It's too bad that
>the ANSI C committee decided to disallow assignment of (char **) to
>(const char **), but those are the rules.  Complain to X3J11 (i.e.  the
>ANSI C standard committee) if you don't like it.

I wrote:
>  The ANSI folks would reply (correctly) that permitting char ** to be
>  assigned to const char** would open a hole in the type system you could
>  drive a truck through.  Your homework assignment, Ron, is to write a
>  function that, given your proposed change...

Ron replies:
>WAIT A SECOND JOE!  You've obviously gotten very confused somewhere along
>the line.

So have you, Ron, so have you.  The original poster, Marko Rauhamma, did
not want to assign a char** to a const char**.  Quoting now:

"The problem is that a `char **' variable cannot be assigned to a `const
char *const *' variable."

>I am not proposing any change to the language (although the original poster
>may have been desiring to propose one).

You need to work in your language in that case.  In my book, when someone
who has spent much of his net career attacking the judgment of standards
committees says "It's too bad that the ANSI committee decided ... but
those are the rules", it doesn't seem like a great leap to assume that
an assertion is being made that the committee made a mistake.

However, as Fergus Henderson points out, the ANSI C++ committee has fixed
this (add this to your list of C/C++ compatibilities if you like, though
it won't break any C program that C++ previously accepted).

The problem is this: I want to write a function that can handle an argument
of type char** as well as of type const char**.  But it is unsafe to
assign either to the other.  However, it's easy to show that it is safe
to assign either to a "const char * const *" variable, since for the
latter neither the text nor any of the underlying pointers may be changed.
Thus in C++ you'll be able to say

int foo (int argc, const char * const * argv);

and give an actual second argument either of const char** or of char**.

Given that that this has been blessed by one standards committee, it might
be considered for a GNU C extension; I don't see it as being a high priority
item though.


--
Joe Buck	jbuck@ohm.EECS.Berkeley.EDU
Technical Details
Message-ID: <23jkpr$ggv@agate.berkeley.edu>
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!uunet!cs.utexas.edu!math.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!forney.eecs.berkeley.edu!jbuck
References: <9308020205.AA00413@ohm.EECS.Berkeley.EDU>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,e12f0e12c9950414,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-08-02 14:49:08 PST
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!uunet!cs.utexas.edu!math.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!forney.eecs.berkeley.edu!jbuck
From: jbuck@forney.eecs.berkeley.edu (Joe Buck)
Newsgroups: gnu.gcc.help
Subject: Re: Bug in C standard
Date: 2 Aug 1993 16:58:40 -0400
Organization: University of California at Berkeley
Lines: 55
Sender: daemon@cis.ohio-state.edu
Distribution: gnu
Message-ID: <23jkpr$ggv@agate.berkeley.edu>
References: <9308020205.AA00413@ohm.EECS.Berkeley.EDU>