strings and constness

Erik Hovland erik at hovland.org
Sun Jun 18 01:07:47 UTC 2006


On Sat, Jun 17, 2006 at 07:58:00PM -0400, Rob Landley wrote:
> On Tuesday 13 June 2006 11:19 pm, Erik Hovland wrote:
> > > >See my post and patch to utils.c and utils.h where I did this for
> > > >another function:
> > > >http://busybox.net/lists/busybox/2006-June/022287.html
> > >
> > > I see that now, I thought it was a typo since my compiler threw a warning
> > > about it.  If there are valid space savings for it, we need to find a way
> > > to suppress the warning.
> >
> > If you want to make the string const, put the const before the *.
> 
> Also, when we have to typecast our way around this crap (as in 
> skip_whitespace() in libbb where half the users typecast the return value 
> back to a normal char * when they use it, but it _is_ a normal char * to 
> begin with...)
> 
> I'm not a fan of const.  Really.

I think that the compiler could care a flip about whether you are a
fanatic of const. I could really care less about const either. I think
you probably agree that there is only one thing that will decide whether
const should be used or not, size of binary.

But if one is going to use const, they should do it right and at least
understand what the placement of const regarding the * operator does to
the string. I have submitted two patches in so many weeks that
corrected const. Both came after commits that put const in the wrong
spot and generated warnings. I think we all could do without those sorts
of mistakes so we can get to doing the work we want to do.

E

-- 
Erik Hovland
mail: erik at hovland.org
web: http://hovland.org/
PGP/GPG public key available on request



More information about the busybox mailing list