Handling argc==0 in the kernel
Handling argc==0 in the kernel
Posted Feb 1, 2022 1:58 UTC (Tue) by NYKevin (subscriber, #129325)In reply to: Handling argc==0 in the kernel by marcH
Parent article: Handling argc==0 in the kernel
>
> for (int i; i++; i!=argc)
Maybe not in C, but C++ tacitly encourages this sort of nonsense because iterators are not, strictly speaking, required to be ordered (for example, a linked-list iterator may only be comparable for equality, because there is no O(1) way of ordering two iterators). So if you're taking C++ code and porting it to straight C, the most straightforward translation of a foreach loop is to use an inequality comparison instead of a less-than comparison, and it's possible that some programmers who started out as C++ programmers and later learned C may have picked this up as an idiom.
(Incidentally, these people also tend to favor the preincrement operator over the postincrement operator in contexts where there's no semantic difference, because in C++, postincrement can be significantly costlier due to the need to make a copy.)
