Mail Archives: djgpp/1999/02/12/18:07:41
Which will cause cc1plus to generate better code?
inline int myclass::myfunc (int j) { return j*j*j; }
inline int myclass::myfunc (const int &j) { return j*j*j; }
My guess would be the latter, since the latter when inlined won't make a
copy of the argument passed. However, it might be that at high -O settings
cc1plus will spot that the first version doesn't modify j and silently
compile it like the second version.
If so, this leads me to ask: under what circumstances will the compiler be
smart enough to detect that an inline function passed an argument of a
builtin type doesn't modify it and avoid making an unnecessary copy?
This leads me to ask: when writing short inline functions, is it better for
code optimization to pass builtin data types (bool, int, double, etc.) and
pointers by value or by reference? (Yuck, passing pointers by reference,
well I'll do it if it means real speed gains in tiny inline functions that
get invoked a great deal.)
--
.*. "Clouds are not spheres, mountains are not cones, coastlines are not
-() < circles, and bark is not smooth, nor does lightning travel in a
`*' straight line." -------------------------------------------------
-- B. Mandelbrot |http://surf.to/pgd.net
_____________________ ____|________ Paul Derbyshire pderbysh AT usa DOT net
Programmer & Humanist|ICQ: 10423848|
- Raw text -