Re: Need for const in function argument list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Glynn Clements wrote:

If a pointer parameter is declared as const, you can pass either const
or non-const pointers. If it isn't declared as const, then you can
only pass non-const pointers, not const pointers.


For that alone please use const when it is needed. Some moron I had to work with once wrote a wrapper for some printing functions and in the most significant of his functions he had
void PrintText(char*){/...}
and there was no way for me to write:
PrintText("Hello World");
in my code, I had to use the ugly:
PrintText(const_cast<char*>("Hello World"));
because of someone else's ignorance.
--
Make it work. Make it fast. Make it right. Pick any two...
-
: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux