Subject: Re: bogus CC warning?
To: Aidan Cully <email@example.com>
From: None <firstname.lastname@example.org>
Date: 04/11/1999 02:05:57
In message <19990411023835.A580@xanadu.kublai.com>, Aidan Cully writes:
>(I know this belongs on tech-toolchain, but I'm not subscribed their, so
>please Cc: me in all replies.. Thanks.)
Okay. This is an egcs thing; it has more complicated warnings for
>> #include <string.h>
>> #include <stdio.h>
>> typedef unsigned char array;
>> void proto(const array *string, array *string2);
>> int main(int argc, char *argv)
>> array str1, str2;
>> proto(&str1, &str2);
>> test.c:13: warning: passing arg 1 of `proto' from incompatible pointer type
Okay, let's see what the types are.
'str1' is 'array', so &str1 is 'array *'. This is not the same as
'const array *'. However, normally, that wouldn't be a problem, or I'm too
tired to think straight. (This is not atypical; you can generally get a
fair amount of bloodshed by bringing up the interactions of const, typedef,
and default promotions in front of three or four C people.)
>> void proto(string, string2)
>> const array *string;
>> array *string2;
>> if (string == string2)
>> test.c:22: warning: comparison of distinct pointer types lacks a cast
This is the same thing.
>> proto(string2, string2);
>> test.c:24: warning: passing arg 1 of `proto' from incompatible pointer type
And, once again, same thing.
>I was able to build a patch that fixed this, if it is, indeed, a bug..
>(I don't have any C-references, and I don't feel like looking through
>one even if I did.) Can someone in the know please confirm with me
>that this behaviour _is_ a bug, and not defined C behaviour?
It is not forbidden to emit additional diagnostic messages. I would generally
consider it a bad thing for a program to consider 'const foo' and 'foo'
incompatible types. (Note, however, that 'pointer to const foo' and 'pointer
to foo' really are separate types.)
I'm *thinking* this warning is misleading - and yet, it only happens in
the case that confuses me. ;-) If I have a function declared as taking
a const argument, and pass it a non-const-qualified thing, no complaints.
So, I'm not sure why we're getting the warning that we are.
>the attached patch (which I installed on my system to get kerberos
>building again) is correct? In particular, I'm not sure that in all
>the instances that comptypes gets called that type1 is always the lhs
>and type2 is always the rhs..
Can't help you at all on this one.