Re: const fixes seek commit approval
- From: Aaron Digulla <digulla wi-pc44 fh-konstanz de>
- To: gtk-devel-list redhat com
- Subject: Re: const fixes seek commit approval
- Date: Wed, 28 Oct 1998 10:39:11 +0100
Quoting Havoc Pennington (rhpennin@midway.uchicago.edu):
> > 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
> way:
>
> 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.
In this case, I'd say thet gtk_label_get() has a wrong prototype: You
wouldn't want that the user changes the label via string, will you ?
> > 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... ;-)
Well, this is not the fault of the patch but of GCC. GCC doesn't have
meaningful error messages (example: The famous "Parser error before"
if you use an unknown type).
Sidenote: For a good discusion of "const correctness", see the C/C++ FAQ
section 18 at http://www.informatik.uni-konstanz.de/~kuehl/cpp/cppfaq.htm/
--
Dipl. Inf. (FH) Aaron "Optimizer" Digulla Assistent im BIKS Labor, FB WI
"(to) optimize: Make a program faster by FH Konstanz, Brauneggerstr. 55
improving the algorithms rather than by Tel:+49-7531-206-514
buying a faster machine." EMail: digulla@fh-konstanz.de
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]