On poniedziałek 29 lipiec 2002 09:59 am, Edwin Leuven wrote:
> ...completely unrelated and just wondering what the experts say.
>
> How about:
>
> for(int i = 0; i < tabular->rows(); ++i) {
>     for(int j = 0; j < tabular->columns(); ++j) {
>
>
> as opposed to:
>
> int const r = tabular->rows();
> int const c = tabular->columns();
> for(int i = 0; i < r; ++i) {
>     for(int j = 0; j < c; ++j) {
>
> What is better? would it make a difference performance wise?

For a good compiler it should make no difference, as long as
(1) Tabular::rows() is const, and Tabular::columns() as well -- i.e. so that 
those have no side-effects, and assuming that you don't touch your tabular in 
the loop.

But I doubt that any such good compiler exists.

So I'd better use the second version.

Cheers, Kuba Ober

(1) assuminfg tabular is of Tabular * type, if not, replace with something 
correct rather than my guess ;-)

Reply via email to