[cairo] Const correctness?

Dan Raymond draymond at foxvalley.net
Sat Feb 18 19:18:37 UTC 2017


C supports const function parameters and the compiler will enforce it if 
you are including the correct header file.  You are conflating const 
with function overloading.  The prototypes below are equivalent between 
C and C++.  The only difference is that the C++ version uses name 
mangling to make the function symbols unique while in C you must do that 
yourself.

C:

void foo(int *ptr);

void const_foo(const int *ptr);

C++:

void foo(int *ptr);

void foo(const int *ptr);


On 2/17/2017 12:07 PM, Behdad Esfahbod wrote:
> Plus, in C there's no way to correctly annotate a function like 
> cairo_reference().  In C++ you can define a version taking const and a 
> non-const version.  In C, you can't.
>
> On Fri, Feb 17, 2017 at 10:44 AM, Lawrence D'Oliveiro 
> <ldo at geek-central.gen.nz <mailto:ldo at geek-central.gen.nz>> wrote:
>
>     On Fri, 17 Feb 2017 09:01:44 -0800, Bryce Harrington wrote:
>
>     > Perhaps at that time the usefulness of
>     > const'ing parameters was not held as a consensus of the
>     developers at
>     > that time.
>
>     You have to distinguish between interface and implementation. C
>     doesn’t
>     offer any way to say that any modifications to the object are not
>     visible to the user.
>     --
>     cairo mailing list
>     cairo at cairographics.org <mailto:cairo at cairographics.org>
>     https://lists.cairographics.org/mailman/listinfo/cairo
>     <https://lists.cairographics.org/mailman/listinfo/cairo>
>
>
>
>
> -- 
> behdad
> http://behdad.org/
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20170218/eb29127d/attachment.html>


More information about the cairo mailing list