Re: const fixes seek commit approval

On Tue, 27 Oct 1998, Tim Janik wrote:
> nope, don't change such occourancs to const gchar**, the same reasons as
> for normal return values do apply here as well, it's even a little more
> serious. 

The difference is that in the return value case, if you do it the right

const gchar* string;
string = gtk_foo();

you get no warning. But if you do this:

const gchar* string;
gtk_label_get(label, &string); /* traditional non-const gtk_label_get */

it produces the same "incompatible pointer type" warning. So while the
non-const return value is basically harmless for people using const
properly, in this case you are *required* to cause warnings for either the
people using const or the people not using const. There is no way around
screwing one of them. 

> gchar *string;
> get_const_string ((gchar**) &string);

This is a stupid way to write the code. I fixed these all over Gtk when I
changed gtk_label_get etc., and the correct fix is to declare 'string' as
'const gchar*'. FWIW, in no case was the same variable used as both const
and non-const; i.e., in all the Gtk code, I don't think I had to add a new
variable to solve this problem. I used no casts either. 
> the requirement of this cast, just to convert from (const gchar**) to
> (gchar**)  is even more fatal, since the compiler is unable to perform
> additional checks of wether it's actually gchar* or gchar** that's
> passed. 

Well, this is your own fault for using casts instead of declaring your
variables properly. But ignoring that, this same argument applies in
reverse, because one group of people has to cast: those using const or
those not using it. There is no way to make everyone happy in this case.

> as an aside, the compiler warning produced in such a case goes along the
> lines of
> ...passing argument 1 of `foo' from incompatible pointer type...
> not even mentioning that it's actually const-issue that's going on here.

True, this is a vague warning. Though it is technically true, and
const is technically part of the type, not a separate thing. And it would
probably be good for many C programmers to have to learn this... ;-)

> so the worst thing to do is converting gchar** args to const gchar** args,
> especially if normal return values are already not fully const enforcing.

It sounds like you're making a slippery slope out of the non-const return
values. As I understand it, those are only OK because they are not very
annoying for people using const properly, so we might as well be nice to
those using it wrong. In the args case, we can either burden people using
it properly, or people using it wrong; a decision has to be made.

I'm getting mixed signals here, I need agreement between you and Owen so I
know what to do. 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]