Is this a valid ANSI program?

Stephen J. Friedl friedl at mtndew.Tustin.CA.US
Wed Jun 26 12:46:28 AEST 1991


Hi folks,

     We're compiling our code on everything these days, and
lately a vendor is claiming that the following program is
*required* by ANSI to provoke a compiler warning:

	void foo(const char **xxx)
	{
		/* nothing */
	}

	main()
	{
	char	**p = 0;

		foo(p);
	}

The compiler claims that the argument /p/ to the function foo()
is incompatible with the prototype, and I just don't believe it.
The parameter to the foo function simply promises that it won't
modify the chars pointed to by the pointer-to-pointer passed as
an arg.  [yes, I know that "const char *const *xxx" would be an
even stronger statement: that fails the same way]

The same kind of problem is likely responsible for this code

	extern void *malloc();

	main()
	{
	const char **p;

		p = (char **)malloc(1);
	}

producing the same kind of warning in the assignment.

The vendor claims that the ANSI Standard requires these warnings.
While the assign-nonconst-to-const works for one level of pointer
defereferencing, they say that anything beyond the first level
must be identically qualified.  They said something like this was
a misfeature in the Standard (!).

I can imagine things being treated differently for qualifiers
applied to the base type and those applied to the derived types,
but I really can't find anything in my 7 Dec 1988 draft Standard
on this one.  Can anybody help me?  While this is by no means any
kind of proof, we've never seen this on any other ANSI compiler
before.

Replies via email if you don't mind, or to comp.lang.c if of
general interest.  I just had uunet turn my feed of this group,
so very fast posted responses may not make it to my machine.

     Steve "getting back into Usenet" Friedl

-- 
Steve Friedl, Resident Wizard  /  friedl at vsi.com  /  {uunet attmail}!vsi!friedl
V-Systems, the VSI*FAX people /  Santa Ana, CA  / +1 714 545-6442v 545-7653 fax

Two things for sure: death and faxes



More information about the Comp.lang.c mailing list