Re: [eigen] Signed or unsigned indexing |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
Hey!
Am 20.01.2017 um 19:41 schrieb Benoit Jacob:
That leads to one of the strongest arguments in favor of unsigned: at
least, that has well-defined (wrapping) overflow behavior. That might
be 'broken', but it isn't nearly as dangerous as the undefined
behavior of signed overflow!
But if you take this point of view the unsigned-signed promotion and
comparison rules are just a as big hazard. We should never be forced to
really think about them.
E.g. try to wrap your had around the following:
signed int a{-1 };
unsigned int b{1};
according to C++ language rules now a < b is false.
This is possible through consistent use of one type of indexes, sizes,
slices etc. And negative slices and strides have well-defined meaning
and should be allowed, so they must be signed. Deciding on a
case-by-case basis forces peoples into all the nitty gritty details of
integer promotion and comparision, which is exactly what we should IMHO
protect users from.
So that argument works both ways.
Martin