[EMAIL PROTECTED] wrote: > 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.
And, with modern systems, its hard to tell whether use of "register" is worthwhile either. The "register" hint may often mean that the compiler winds up consuming a value in a register, and can't schedule the register for somewhere that is even *hotter*. IMO, most of these "hints" to the compiler should be avoided, because in a lot of cases the programmer "guesses" poorly. (The other thing is that sometimes the "guess" is good on one architecture, perhaps one with more registers, and less accurate on another one that has fewer registers.) -- Garrett _______________________________________________ opensolaris-code mailing list opensolaris-code@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/opensolaris-code