const read 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:33 UTC
Read the original article Hit count: 258

Filed under:

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 read-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 read-only local copies, as it confirms to anyone reading my code that it is a read-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

Related posts about c