is using const in function declaration a lot good?
Well, using const in a function decloration is just a way of enforcing your design. It''s really no different than using different access modifiers in class declorations (public, private, etc...). You don''t have to use them, but it''s a good way of insuring that your data and functions are used like you intend them to be used. Think of it as a safty check.
July 28, 2000 12:14 AM
Using "const" in front of parameters being
passed to a function is a very good idea.
Knowing that a variable is to remain
unchanged through the function allows the
complier to more aggresively optimise the code
within the function.
passed to a function is a very good idea.
Knowing that a variable is to remain
unchanged through the function allows the
complier to more aggresively optimise the code
within the function.
I'll go with I-Shaolin.
And if you use a good compiler, bet it will also make some more optimizations, so your program will run faster
It's always good to use const, in any case!
But in parameters for some standard functions for example need a const char *, but ask for a normal char *. If you would use this function with your nice const char * variable, you would need an extra type-conversion
Sometimes programmers are just too lame...
Edited by - baskuenen on July 28, 2000 1:18:58 AM
And if you use a good compiler, bet it will also make some more optimizations, so your program will run faster
It's always good to use const, in any case!
But in parameters for some standard functions for example need a const char *, but ask for a normal char *. If you would use this function with your nice const char * variable, you would need an extra type-conversion
Sometimes programmers are just too lame...
Edited by - baskuenen on July 28, 2000 1:18:58 AM
Good compiler understand "const" as hint for optimization.
For example, if you declare pointer as
(.., const ...*, )
compiler is free to store values from this array in registers and don''t have to worry about memory aliasing.
For example, if you declare pointer as
(.., const ...*, )
compiler is free to store values from this array in registers and don''t have to worry about memory aliasing.
July 28, 2000 02:06 AM
quote: Original post by I-Shaolin
Well, using const in a function decloration is just a way of enforcing your design. It''s really no different than using different access modifiers in class declorations (public, private, etc...). You don''t have to use them, but it''s a good way of insuring that your data and functions are used like you intend them to be used. Think of it as a safty check.
Hello there, You sound very intelligent. Do you get hit on a lot because of it?
-Shadow
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement