S
Snis Pilbor
Whats the point of making functions which take arguments of a form like
"const char *x"? It appears that this has no effect on the function
actually working and doing its job, ie, if the function doesn't write
to x, then it doesnt seem like the compiler could care less whether I
specify the const part. Quite the opposite, if one uses const
liberally and then later goes back and changes the functions, headaches
will inevitably occur as one tries to compile and the compiler gripes
because now suddenly you ARE writing to x, so you have to go back and
remove the const keyword, and this might mean painstakingly removing it
from dozens of lines if the function in question is deeply nested
amidst a family of functions that call eachother and all have 'const'
keywords.
Is const, in this context (ie passing const arguments to functions)....
1. A Java-like "babysitter" keyword based on the premise that all
programmers are idiots and must have their hands held at all times?
2. Used to alert the compiler that some kind of extra optimization is
possible, which wouldn't be possible if the data in question were
manipulated? And if so, exactly what sort of optimization would this
be?
3. About as useful as a comment, with no other purpose but as a little
yellow sticky note saying "this function should act nondestructively on
this particular thing"?
I always assumed it was some combination of 1 and 3 and so I tend to
never, ever use the thing...
Thanks, this is something I've always been curious about =)
Snis Pilbor
"const char *x"? It appears that this has no effect on the function
actually working and doing its job, ie, if the function doesn't write
to x, then it doesnt seem like the compiler could care less whether I
specify the const part. Quite the opposite, if one uses const
liberally and then later goes back and changes the functions, headaches
will inevitably occur as one tries to compile and the compiler gripes
because now suddenly you ARE writing to x, so you have to go back and
remove the const keyword, and this might mean painstakingly removing it
from dozens of lines if the function in question is deeply nested
amidst a family of functions that call eachother and all have 'const'
keywords.
Is const, in this context (ie passing const arguments to functions)....
1. A Java-like "babysitter" keyword based on the premise that all
programmers are idiots and must have their hands held at all times?
2. Used to alert the compiler that some kind of extra optimization is
possible, which wouldn't be possible if the data in question were
manipulated? And if so, exactly what sort of optimization would this
be?
3. About as useful as a comment, with no other purpose but as a little
yellow sticky note saying "this function should act nondestructively on
this particular thing"?
I always assumed it was some combination of 1 and 3 and so I tend to
never, ever use the thing...
Thanks, this is something I've always been curious about =)
Snis Pilbor