const ready only local copies
Posted
by robUK
on Stack Overflow
See other posts from Stack Overflow
or by robUK
Published on 2010-05-31T13:22:12Z
Indexed on
2010/05/31
13:22 UTC
Read the original article
Hit count: 193
c
Hello
gcc 4.4.4 c89
I am just wondering is it worth passing a const into a function.
i.e.
void do_something(const char *dest, const int size)
The size is a ready-only so I don't want to change it. However, some developers never have this as const has it is a local copy that is being used. The pointer is const as you can change the value in the calling routine.
I always have a const on ready-only local copies, as it confirms to anyone reading my code that it is a ready-only variable. And also, when coding I don't make the mistake of changing it without realizing.
Many thanks for any suggestions,
© Stack Overflow or respective owner