vlad wrote: |
---|
So you write something as for ( int* first = a, last = a + N; first != last; ++first ) { /*...*/ } Oops! I made an error. int* is not the type of last!:) |
The usual error of beginners that they follow your style and write for example int* a[10]; |
int*
is so clear.T a[10];
creates an array of 10 T's. So if the type is a pointer (T==int*):int* a[10];
this creates an array of pointers. It's exactly what anyone would expect. The pointer is part of the type, and you have an array of it. There is nothing confusing about that code.while they wanted to write int ( *a )[10]; |
int (*a)[10];
is confusing syntax any way you slice it.
|
|
|
|
@Disch vlad wrote: So you write something as for ( int* first = a, last = a + N; first != last; ++first ) { /*...*/ } Oops! I made an error. int* is not the type of last!:) I agree that cramming too much into a single for statement is bad style and makes code more difficult to read... which is why I would never write code like the above. Generally I find that the comma operator leads to many more errors/confusion than the way you declare your pointers. |
vlad wrote: |
---|
When someone is doing some stupidy he has to do another stupidy that to justify the first stupidy. |
int* i
. I generally avoid declaring more than one variable in a line, and if I do I'm well aware of the issue with pointers and pay special attention to it.
int* p
it looks like * is associated with its left, but this is wrong when you use int const* p
. By personal preference I align the pointer to what it actually is associated with: int *const p
@Catfish4 Though in the example I showed there is no comma operator. Ouch. |
vlad from moscow wrote: |
---|
What does mean this "Ouch" in this case?:) |