l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2010 Feb 28 23:29

The following is an archive of a post made to our 'vox mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox] things that really suck about C!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox] things that really suck about C!

On Sun, Feb 28, 2010 at 10:49 PM, Carl Boettiger <cboettig@gmail.com> wrote:
>> One calls a function and the arguments are passed by value. Call a
>> function with an array as an argument, and feel free to modify its
>> contents!
> so declaring an array as const prevents this, func(const double * a).  I
> understand that this also helps the compiler make optimizations it cannot do
> when you don't use const.  I think you could still modify the contents of
> the array by first copying the pointer though,
> double * b = a;
> b[i] = something new.
> So there's also the modifier "restrict", which I believe would prevent this,
> and again helps out the compiler do smart things.  Others can probably
> confirm/correct this?  Is it good practice to use these modifiers as often
> as possible/appropriate?

Yes, using const as much as possible really helps. When I see const
used correctly and as often as possible, it makes me more confident
that the functions I'm calling are well written.

Google's internal C++ style guidelines agree:

I've worked on projects before where others didn't agree, and they'd
never mark parameters as const in any way. Then my functions that call
theirs can't mark parameters as const, and so on, up the call chain.
In C++ world, the same problem happens when methods aren't marked as
const when they should be.

vox mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.