const question, take II

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Harald Welte laforge at gnumonks.org
Thu Mar 17 07:06:32 UTC 2016


Hi Neels,

On Wed, Mar 16, 2016 at 11:22:11PM +0100, Neels Hofmeyr wrote:
> On Wed, Mar 16, 2016 at 11:28:30AM +0100, Harald Welte wrote:
> > Why does gsm48_hdr_pdisc() not take a 'const struct gsm48_hdr *'
> > argument in the first place?  I don't think it modifies the contents of
> > the structure...
> 
> Yes, Holger has applied the patch with exactly that change.
> 
> Yet this has me confused. A while back I concluded that C doesn't allow
> passing non-const instances to functions that expect a const arg. 

We do that all the time in Osmocom projects.  Especially for functions
that have input pointers (should be "const foo *") and output pointers
(should be "foo *), you can easily safeguard agaist some common cases
where the caller swaps the arguments this way.

This is standard practise, see the definition of memcpy:

 void *memcpy(void *dest, const void *src, size_t n);

> http://lists.osmocom.org/pipermail/openbsc/2016-January/001051.html
> http://lists.osmocom.org/pipermail/openbsc/2016-January/001055.html
> 
> How is this different from the conclusion that Jacob confirmed two months
> ago? Is it int (primitives) vs. struct??

from a quick look, the above discussion was about passing the address of
a pointer, and of course if you pass that into a function, you expect
the function to be able to modify the pointer stored at that address?
-- 
- Harald Welte <laforge at gnumonks.org>           http://laforge.gnumonks.org/
============================================================================
"Privacy in residential applications is a desirable marketing option."
                                                  (ETSI EN 300 175-7 Ch. A6)



More information about the OpenBSC mailing list