Re: Const correctness?
Dan Raymond <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <[email protected]> |
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 > <[email protected] <mailto:[email protected]>> 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 > [email protected] <mailto:[email protected]> > https://lists.cairographics.org/mailman/listinfo/cairo > <https://lists.cairographics.org/mailman/listinfo/cairo> > > > > > -- > behdad > http://behdad.org/ > > -- cairo mailing list [email protected] https://lists.cairographics.org/mailman/listinfo/cairo