Topic: Conversion illegal or compiler bug?


Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Sat, 24 Dec 1994 04:22:30 GMT
Raw View
clamage@Eng.Sun.COM (Steve Clamage) writes:

>michaelr@ios.com (Michael Rosenthal) writes:
>
>>void f(const char * const *);
>>
>>void g()
>>{
>>char **p;
>>f(p);    // MS compiler will not perform this conversion.
>>}
>
>Microsoft is entirely correct. That is invalid code in both C and C++.

Microsoft *used* to be entirely correct.  The code used to be invalid in
both C and C++.  It is still invalid in C, but in C++, according to
recent copies of the ANSI/ISO C++ committee's working draft, it is now valid.
(The relevant section in the September 1994 draft is 4.4/2.)

Note that you do need the second `const' in the declaration of f() -
example such as

 void f(const char **);
 void g(char **p) { f(p); }

are still illegal, because they are not safe.

--
Fergus Henderson - fjh@munta.cs.mu.oz.au




Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Wed, 21 Dec 1994 04:10:17 GMT
Raw View
In article <3d042f$3s@engnews2.Eng.Sun.COM> clamage@Eng.Sun.COM (Steve Clamage) writes:
>>void f(const char * const *);
>>char **p;
>>f(p);    // MS compiler will not perform this conversion.
>
>Microsoft is entirely correct. That is invalid code in both C and C++.

 It's invalid in ISO C and ARM C++ but valid
in WP C++. The conversion is safe and should be performed
implicitly: its a standard conversion. See 4.4/2.
--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,
        81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21
        NSW 2037, AUSTRALIA     Phone: 61-2-566-2189




Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Fri, 23 Dec 1994 04:53:30 GMT
Raw View
michaelr@ios.com (Michael Rosenthal) writes:

>The following is rejected by the Microsoft Visual C++ compiler:
>/********************************/
>void f(const char * const *);
>
>void g()
>{
>char **p;
>f(p);    // MS compiler will not perform this conversion.
>}
>/********************************/
>
>Microsoft claims this behavior is correct and claims that ARM 13.2
>supports them. My interpretation of the ARM does not agree (my other
>compilers don't either.) Comments anyone?

Microsoft's interpretation of the ARM is correct.
The rules in the ARM are supposed to be the same as the rules in the C
standard for this example.  Your code is not legal C code.
In this respect, Microsoft's compiler conforms to the ARM.

However, the rules in the ANSI/ISO C++ committee's working draft are different,
and allow this conversion.  Hence Microsoft's compiler does not conform to
the working draft.

--
Fergus Henderson - fjh@munta.cs.mu.oz.au




Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 18 Dec 1994 01:42:39 GMT
Raw View
michaelr@ios.com (Michael Rosenthal) writes:

>The following is rejected by the Microsoft Visual C++ compiler:
>
>void f(const char * const *);
>
>void g()
>{
>char **p;
>f(p);    // MS compiler will not perform this conversion.
>}

Microsoft is entirely correct. That is invalid code in both C and C++.
I believe the FAQ for comp.lang.c covers this issue (which comes up
here about once a month).
--
Steve Clamage, stephen.clamage@eng.sun.com




Author: michaelr@ios.com (Michael Rosenthal)
Date: 16 Dec 1994 05:30:07 GMT
Raw View
The following is rejected by the Microsoft Visual C++ compiler:
/********************************/
void f(const char * const *);

void g()
{
char **p;
f(p);    // MS compiler will not perform this conversion.
}
/********************************/

Microsoft claims this behavior is correct and claims that ARM 13.2
supports them. My interpretation of the ARM does not agree (my other
compilers don't either.) Comments anyone?

- Michael Rosenthal
michaelr@ios.com