Roland Mainz writes: > Garrett D'Amore wrote: >> Roland Mainz wrote: >> > James Carlson wrote: >> >> Garrett D'Amore writes: >> >>> Piotr Jasiukajtis / estibi wrote: >> >>> >> > [snip] >> > >> >> - Don't use 'const' with non-pointer arguments. It's silly there. >> > >> > Why ? It gives the compiler valueable hints how the argument is/should >> > be used. AFAIK this was one of the early things which even the old C >> > compilers (long before ANSI C) tried to optimize when they found a >> > |const| variable. The old SAS/C compiler documentation even recommends >> > it... >> >> Modern compilers shouldn't need the declaration to optimize it -- they >> can tell if the value ever changes within the function being compiled. >> >> And since variables are passed by value, the const declaration means >> nothing to the caller as well. >> >> So while these types of hints may be useful for ancient compilers, the >> state of the art has long since moved past that point. > > Erm... I sightly disagree at the point that it is "useless" - like the > |register| keyword it may give the compiler a hint which variables > should be priorised for register or fast memory (e.g. vector machines) > usage or when tracking the scope of values (e.g. the compiler doesn't > have to look further into the function's body just to figure out whether > the associated variable storage is being modified or not (which makes > sense for application-wide inlining like done with XIPO&co.)). > Rather than speculate, measure! Profile some examples.
I don't know of any compiler where a const non-pointer parameter makes any difference. Ian. _______________________________________________ opensolaris-code mailing list opensolaris-code@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/opensolaris-code