C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Variables in for loop (style issue)
Goto page 1, 2, 3 ... 12, 13, 14  Next
 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Maciej Sobczak
Guest





PostPosted: Thu May 04, 2006 10:21 am    Post subject: Variables in for loop (style issue) Reply with quote



Hi,

Consider this:

for (size_t i = 0; i != v.size(); ++i)
{
// do something with v[i]
}

The above is considered to be a bad practice, because it calls v.size()
every iteration and sugggests that the size of the vector might change,
which is actually not the intent.
The possible solution (and even stated as a rule in one coding standard) is:

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

The above, however, breaks another coding standard rule saying that
variables used to control the loop should be declared in the scope of
the loop without polluting the enclosing scope (that's what the scoping
rules in for are about, right?).

The other solution might be this:

for (size_t i = 0, vSize = v.size(); i != vSize; ++i)
{
// do something with v[i]
}

But this, in turn, breaks another coding standard rule saying that
everything that could be const must be const (above, vSize cannot be
const, because it's declared together with i as non-const size_t).

The ultimate solution might be this:

{ // artificial enclosing scope

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

}

But it smells unpleasantly because of this additional pair of braces and
the resulting indentation.

Conclusion [*] - there's no way to do it *right*.

The following might please me:

// not C++:
for ( {size_t i = 0; const size_t vSize = v.size(); }; i != vSize; ++i)
{
// do something with v[i]
}

What is your own style choice? Why?


[*] "Conclusion is the point where you got tired of thinking."

--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Bob Hairgrove
Guest





PostPosted: Thu May 04, 2006 10:21 pm    Post subject: Re: Variables in for loop (style issue) Reply with quote



On 4 May 2006 06:05:20 -0400, Maciej Sobczak <no.spam (AT) no (DOT) spam.com>
wrote:

Quote:
Hi,

Consider this:

for (size_t i = 0; i != v.size(); ++i)
{
// do something with v[i]
}

The above is considered to be a bad practice, because it calls v.size()
every iteration and sugggests that the size of the vector might change,
which is actually not the intent.
The possible solution (and even stated as a rule in one coding standard) is:

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

The above, however, breaks another coding standard rule saying that
variables used to control the loop should be declared in the scope of
the loop without polluting the enclosing scope (that's what the scoping
rules in for are about, right?).

The other solution might be this:

for (size_t i = 0, vSize = v.size(); i != vSize; ++i)
{
// do something with v[i]
}

But this, in turn, breaks another coding standard rule saying that
everything that could be const must be const (above, vSize cannot be
const, because it's declared together with i as non-const size_t).

The ultimate solution might be this:

{ // artificial enclosing scope

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

}

But it smells unpleasantly because of this additional pair of braces and
the resulting indentation.

Conclusion [*] - there's no way to do it *right*.

The following might please me:

// not C++:
for ( {size_t i = 0; const size_t vSize = v.size(); }; i != vSize; ++i)
{
// do something with v[i]
}

What is your own style choice? Why?


[*] "Conclusion is the point where you got tired of thinking."

One big problem is the fact that not all containers are vectors, and
calling size() is very inefficient for almost all containers except
for std::vector.

How about this:

for (size_t i=0, std::vector<whatever_v_is>::iterator it = v.begin();
it != v.end(); ++i, ++it) {
// etc.
}

I think this solves all the above problems nicely.

--
Bob Hairgrove
NoSpamPlease (AT) Home (DOT) com


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Ulrich Eckhardt
Guest





PostPosted: Thu May 04, 2006 10:21 pm    Post subject: Re: Variables in for loop (style issue) Reply with quote



Maciej Sobczak wrote:
Quote:
for (size_t i = 0; i != v.size(); ++i)
[..]
The above is considered to be a bad practice, because it calls v.size()
every iteration and sugggests that the size of the vector might change,
which is actually not the intent.

I wouldn't interpret too much into it, for me it is just the most simple
form to write a loop.

Quote:
const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
[..]
The above, however, breaks another coding standard rule saying that
variables used to control the loop should be declared in the scope of
the loop without polluting the enclosing scope [...].

True.

Quote:
for (size_t i = 0, vSize = v.size(); i != vSize; ++i)
[...]
But this, in turn, breaks another coding standard rule saying that
everything that could be const must be const (above, vSize cannot be
const, because it's declared together with i as non-const size_t).

{ // artificial enclosing scope
const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
[...]
}

But it smells unpleasantly because of this additional pair of braces and
the resulting indentation.

This one and the second one are too cumbersome/confusing, IMHO. Too much to
read and understand.

Quote:
What is your own style choice? Why?

The third one. Making things constant (the argument for #2 and against #3)
is important because then you can skip following code and you _know_ that
the value doesn't change. #3 however allows to keep the scope of the
variable small, so the impact of it not being constant is small.

Another one for you:
#42
for( std::pair<size_t, size_t const> range(0u, v.size());
range.first!=range.second;
++range.first)
[...]

;^)

Uli


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
ThosRTanner
Guest





PostPosted: Thu May 04, 2006 10:21 pm    Post subject: Re: Variables in for loop (style issue) Reply with quote

Maciej Sobczak wrote:
Quote:
Hi,

Consider this:

for (size_t i = 0; i != v.size(); ++i)
{
// do something with v[i]
}

The above is considered to be a bad practice, because it calls v.size()
every iteration and sugggests that the size of the vector might change,
which is actually not the intent.
That's probably micro-optimisation. v.size() is likely to involve a

single fetch from memory, or 2 if v doesn't happen to be a register. It
doesn't 'suggest' that the size of v might change - but it is safe if
it doesn't.

Quote:
The possible solution (and even stated as a rule in one coding standard) is:

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

The above, however, breaks another coding standard rule saying that
variables used to control the loop should be declared in the scope of
the loop without polluting the enclosing scope (that's what the scoping
rules in for are about, right?).

The other solution might be this:

for (size_t i = 0, vSize = v.size(); i != vSize; ++i)
{
// do something with v[i]
}

But this, in turn, breaks another coding standard rule saying that
everything that could be const must be const (above, vSize cannot be
const, because it's declared together with i as non-const size_t).

The ultimate solution might be this:

{ // artificial enclosing scope

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

}

But it smells unpleasantly because of this additional pair of braces and
the resulting indentation.

Conclusion [*] - there's no way to do it *right*.
Well, that's true!


Quote:
The following might please me:

// not C++:
for ( {size_t i = 0; const size_t vSize = v.size(); }; i != vSize; ++i)
{
// do something with v[i]
}

What is your own style choice? Why?

Style 1, because it is the only one that is safe if the size of v
changes.

IF the calculation of the end of the loop is demonstrably expensive
(i.e. something other than v.size()), then I will use one of the other
styles. The amount of braceing depends on the circumstances.

Having said which, I'd like something along the lines of your last
suggestion - I've occasionally had requirements to code a loop where it
is helpful to have 2 variables changing over the course of the loop,
and if they aren't the same type, you have 2 declare one outside the
loop.
Quote:

[*] "Conclusion is the point where you got tired of thinking."

--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Carlos Moreno
Guest





PostPosted: Thu May 04, 2006 10:21 pm    Post subject: Re: Variables in for loop (style issue) Reply with quote

Maciej Sobczak wrote:
Quote:
Hi,

Consider this:

for (size_t i = 0; i != v.size(); ++i)
{
// do something with v[i]
}

The above is considered to be a bad practice, because it calls v.size()
every iteration and sugggests that the size of the vector might change,
which is actually not the intent.

Huh?? This is really new (and shocking!!) to me...

(which I guess gives away what is going to be my answer to your
question later in the message -- I'll try to surprise you, though)


To me, the above does not suggest that v.size() is going to change;
nor am I worried about efficiency issues because of calling the
function -- first, because any difference would most definitely
have no effect on the overall efficiency of the application; and
second, and more importantly, because there really is no difference
whatsoever in runtime performance between the two alternatives
(I think it would have to be a really lousy compiler and/or a
lousy vector implementation so that we could see a noticeable
difference)

Quote:
The possible solution (and even stated as a rule in one coding standard) is:

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

The above, however, breaks another coding standard rule saying that
variables used to control the loop should be declared in the scope of
the loop

Actually, it breaks a more important rule, IMHO -- it just makes
you wonder "what the hell is that and why is this guy overcomplicating
things when we should just put i < v.size()"

Quote:
The other solution might be this:

for (size_t i = 0, vSize = v.size(); i != vSize; ++i)
{
// do something with v[i]
}

But this, in turn, breaks another coding standard rule saying that
everything that could be const must be const

Again, IMHO, it breaks a more important rule -- the rule that says
that it should be possible for a normal human being to read the
code -- the above really borders the realm of write-only code.

Quote:
Conclusion [*] - there's no way to do it *right*.

I disagree -- maybe my threshold for deciding when I'm tired to
think is even before starting to think about it; but the way
I see it, the whole thing is unnecessarily overanalyzed -- using
i < v.size() is the "perfect" solution -- it can not say the
intent in a more obvious way -- how do you know the size of the
container? why, you ask the container, of course; going further
to observe that v.size() is being "called" muiltiple times falls
in the realm of "premature optimization" (well, or rather, the
typical analysis, the typical mentality that leads to premature
optimization issues)

Quote:
What is your own style choice? Why?

Use an STL algorithm!! (did I surprise you? Smile)

Carlos
--

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
benben
Guest





PostPosted: Thu May 04, 2006 10:21 pm    Post subject: Re: Variables in for loop (style issue) Reply with quote

Maciej Sobczak wrote:
Quote:
Hi,

Consider this:

for (size_t i = 0; i != v.size(); ++i)
{
// do something with v[i]
}

The above is considered to be a bad practice, because it calls v.size()
every iteration and sugggests that the size of the vector might change,
which is actually not the intent.

I don't see it this way. The above iteration is common practice and
whether or not the iteration alters the size of the vector should be
made very clear in the loop body.

If for any reason the loop does change the size of the vector then
size() member is actually protecting you.

Quote:
The possible solution (and even stated as a rule in one coding standard) is:

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

The above, however, breaks another coding standard rule saying that
variables used to control the loop should be declared in the scope of
the loop without polluting the enclosing scope (that's what the scoping
rules in for are about, right?).

This case is worse than the previous one since it reduces the
readability considerably.

Quote:

The other solution might be this:

for (size_t i = 0, vSize = v.size(); i != vSize; ++i)
{
// do something with v[i]
}

But this, in turn, breaks another coding standard rule saying that
everything that could be const must be const (above, vSize cannot be
const, because it's declared together with i as non-const size_t).

Same with case 2. Very poor readability. This can possibly confuse
people because they will scratch their head trying to find out why you
do so.

Quote:

The ultimate solution might be this:

{ // artificial enclosing scope

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

}

But it smells unpleasantly because of this additional pair of braces and
the resulting indentation.

Conclusion [*] - there's no way to do it *right*.

The right way is to stick to the first sample, because that's what we
all do and we all understand.

Ideally, the loop body should be concise enough and clear enough to show
that the size of the vector is not changed:


// The following loop clearly shows that the vector's size
// is not changed.
for (size_t i = 0; i < v.size(); ++i)
{
v[i] = 2*v[i];
cout << v[i] << ", ";
}

If what's in the loop occupies more than a page of code, I would
recommend you factor out the body to a functor. Then you can use
std::for_each family to do the loop. This is perhaps the cleanest way:

std::for_each(v.begin(), v.end(), multiply_and_print<int>(2, ", "));

Regards,
Ben

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Nicola Musatti
Guest





PostPosted: Thu May 04, 2006 10:21 pm    Post subject: Re: Variables in for loop (style issue) Reply with quote

Maciej Sobczak wrote:
Quote:
Hi,

Consider this:

for (size_t i = 0; i != v.size(); ++i)
{
// do something with v[i]
}

[discussion and unsatisfactory alternatives snipped]

Quote:
What is your own style choice? Why?

Stick to your original example and only worry about it if I have
documented performance problems.

Because I share your analysis and the first example is at least the
simplest and most common.

Cheers,
Nicola Musatti


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Andrew Koenig
Guest





PostPosted: Thu May 04, 2006 10:21 pm    Post subject: Re: Variables in for loop (style issue) Reply with quote

"Maciej Sobczak" <no.spam (AT) no (DOT) spam.com> wrote in message
news:e3c53n$6en$1 (AT) sunnews (DOT) cern.ch...

Quote:
Consider this:

for (size_t i = 0; i != v.size(); ++i)
{
// do something with v[i]
}

What is your own style choice? Why?

for (v_iter_type it = v.begin(); it != v.end(); ++it) {
// do something with *it
}

I prefer this form because it doesn't use v's random-access ability when it
doesn't need to do so.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Greg Herlihy
Guest





PostPosted: Thu May 04, 2006 10:21 pm    Post subject: Re: Variables in for loop (style issue) Reply with quote

Maciej Sobczak wrote:
Quote:
Hi,

Consider this:

for (size_t i = 0; i != v.size(); ++i)
{
// do something with v[i]
}

The above is considered to be a bad practice, because it calls v.size()
every iteration and sugggests that the size of the vector might change,
which is actually not the intent.

[various alternatives considered]

Quote:
Conclusion [*] - there's no way to do it *right*.

You left out the obvious solution:

for (size_t i = v.size(); i > 0; --i)
{
// do something with v[i-1];
}

Iterating a generic container classes is probably best done with a
generic function. In that case, the program would call a function such
std::for_each and not have a for loop at all. The analogy that I use is
the difference between a mechanical and a solid state device. For loops
have all these "moving parts" to support the loop machinery; but they
have nothing else to do with the purpose of the loop - they are just a
distraction.

So encasing all of that loop logic in a single of code certainly makes
sense:

std::for_each( v.begin(), v.end(),/*do something with each item */);

Of course the difficulty is often devising the third parameter - the
one that does the work. Some programmers will go to any length in order
to use for_each. Personally, I'm not quite so doctrinaire - and I think
better iterators and better function objects are still needed before
the for loop can be declared obsolete.

Greg


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Pete Becker
Guest





PostPosted: Thu May 04, 2006 10:21 pm    Post subject: Re: Variables in for loop (style issue) Reply with quote

Maciej Sobczak wrote:

Quote:

What is your own style choice? Why?



Spending hours internally debating stylistic minutiae is not productive.
Write the loop however you want and get on with your real work.

--

Pete Becker
Roundhouse Consulting, Ltd.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Victor Bazarov
Guest





PostPosted: Thu May 04, 2006 10:21 pm    Post subject: Re: Variables in for loop (style issue) Reply with quote

Maciej Sobczak wrote:
Quote:
Consider this:

for (size_t i = 0; i != v.size(); ++i)
{
// do something with v[i]
}

The above is considered to be a bad practice, because it calls
v.size() every iteration and sugggests that the size of the vector
might change, which is actually not the intent.
The possible solution (and even stated as a rule in one coding
standard) is:

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

The above, however, breaks another coding standard rule saying that
variables used to control the loop should be declared in the scope of
the loop without polluting the enclosing scope (that's what the
scoping rules in for are about, right?).

The other solution might be this:

for (size_t i = 0, vSize = v.size(); i != vSize; ++i)
{
// do something with v[i]
}

But this, in turn, breaks another coding standard rule saying that
everything that could be const must be const (above, vSize cannot be
const, because it's declared together with i as non-const size_t).

The ultimate solution might be this:

{ // artificial enclosing scope

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

}

But it smells unpleasantly because of this additional pair of braces
and the resulting indentation.

Conclusion [*] - there's no way to do it *right*.

The following might please me:

// not C++:
for ( {size_t i = 0; const size_t vSize = v.size(); }; i != vSize;
++i) {
// do something with v[i]
}

What is your own style choice? Why?

I use the third. It seems to have the balance of performance and
coding safety I usually need.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Tomás
Guest





PostPosted: Thu May 04, 2006 10:21 pm    Post subject: Re: Variables in for loop (style issue) Reply with quote

Maciej Sobczak posted:

Quote:
Hi,

Consider this:

for (size_t i = 0; i != v.size(); ++i)
{
// do something with v[i]
}

The above is considered to be a bad practice, because it calls v.size()
every iteration and sugggests that the size of the vector might change,
which is actually not the intent.


I agree that the code is inefficient.


<snip>
Quote:
{ // artificial enclosing scope

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

}

But it smells unpleasantly because of this additional pair of braces
and the resulting indentation.


Your above sample is exactly how I do it. It's perfect in my opinion.

People who come up with "programming rules" tend to be narrow-minded.
Sure, there's things I avoid, but I'm always open to using every feature of
the language to achieve my objective. If you ever tell me that pointers are
bad, or that "goto" is bad, I'll just laugh in your face. I see it as a sign
of weakness that a programmer is hesitant to use the features placed before
them -- it conveys that they feel incompetant.

Why don't they have pointers in Java? Because programmers felt
incompetant.


Quote:
Conclusion [*] - there's no way to do it *right*.

The following might please me:

// not C++:
for ( {size_t i = 0; const size_t vSize = v.size(); }; i != vSize; ++i)
{
// do something with v[i]
}

What is your own style choice? Why?


This is just my own opinion, but I think you need to use your own head
more. Can't you see that the code with the "artifical braces" achieves your
objective perfectly? It has the right scope, and you get to make your object
constant.


-Tomás

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Martin Bonner
Guest





PostPosted: Thu May 04, 2006 10:21 pm    Post subject: Re: Variables in for loop (style issue) Reply with quote

Maciej Sobczak wrote:
Quote:
Hi,

Consider this:

for (size_t i = 0; i != v.size(); ++i)
{
// do something with v[i]
}

The above is considered to be a bad practice, because it calls v.size()
every iteration and sugggests that the size of the vector might change,
which is actually not the intent.
The possible solution (and even stated as a rule in one coding standard) is:

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

The above, however, breaks another coding standard rule saying that
variables used to control the loop should be declared in the scope of
the loop without polluting the enclosing scope (that's what the scoping
rules in for are about, right?).

The other solution might be this:

for (size_t i = 0, vSize = v.size(); i != vSize; ++i)
{
// do something with v[i]
}

But this, in turn, breaks another coding standard rule saying that
everything that could be const must be const (above, vSize cannot be
const, because it's declared together with i as non-const size_t).

The ultimate solution might be this:

{ // artificial enclosing scope

const size_t vSize = v.size();
for (size_t i = 0; i != vSize; ++i)
{
// do something with v[i]
}

}

But it smells unpleasantly because of this additional pair of braces and
the resulting indentation.

Conclusion [*] - there's no way to do it *right*.

The following might please me:

// not C++:
for ( {size_t i = 0; const size_t vSize = v.size(); }; i != vSize; ++i)
{
// do something with v[i]
}

What is your own style choice? Why?

My choice? One of:

for (size_t i = 0; i < v.size(); i++)
{
// do something with v[i]
}

or

for (v_t::iterator it = v.begin(); it != v.end(); ++it)
{
/// use *it or it->
}

Accessing v.size / v.end mutiple times doesn't bother me. I haven't
ever seen profile evidence suggesting it is too slow, and it just
doesn't seem likely to cost very much.

I think the two patterns are common enough (in my code anyway), that
people will just recognize them.

I do quite like the idea of:
BOOST_FOREACH( foo f, v )
{
// Use f instead of v[i] / *it.
}


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Arndt Muehlenfeld
Guest





PostPosted: Fri May 05, 2006 9:21 am    Post subject: Re: Variables in for loop (style issue) Reply with quote

Maciej Sobczak wrote:

Quote:
Hi,

Consider this:

for (size_t i = 0; i != v.size(); ++i)
{
// do something with v[i]
}

The above is considered to be a bad practice, because it calls v.size()
every iteration and sugggests that the size of the vector might change,
which is actually not the intent.

It is always funny to see people do "optimizations" like:

for (int i = max_i; i > 0; --i)
for (int j = max_j; j > 0; ++j)
... some code ...

"because it is faster" which today in most cases is not true,
when, for instance, the above encoded algorithm could be solved
in O(n log n) instead of O(n*n) time.

Since even that is irrelevant for small n and as long as you don't run into
well documented performance problems I like Pete Beckers answer most:

Quote:
Write the loop however you want and get on with your real work

Cheers,
Arndt

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Andrei Alexandrescu (See
Guest





PostPosted: Fri May 05, 2006 9:21 am    Post subject: Re: Variables in for loop (style issue) Reply with quote

Andrew Koenig wrote:
Quote:
for (v_iter_type it = v.begin(); it != v.end(); ++it) {
// do something with *it
}

I prefer this form because it doesn't use v's random-access ability when it
doesn't need to do so.

As it turns out, I had to shy away from this style and use indices in my
code as of late. Current compilers and processor guidelines all advice
preferring indices to pointers (especially when calling functions)
because the compiler has a lot less work to do to figure out there's no
aliasing. It's kinda sad - I do like the iterator style.


Andrei

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Goto page 1, 2, 3 ... 12, 13, 14  Next
Page 1 of 14

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.