Re: [v2 4/6] msvcirt: Implement istream::operator>> for integers.
On 08/02/16 13:37, Iván Matellanes wrote:
+static istream* istream_internal_read_unsigned_integer(istream *this, void *p, int size) +{ + /* size: 0 => short, 1 => int, 2 => long */ + ios *base = istream_get_ios(this); + char buffer[16]; + int num_base; + LONG min_value[3] = {SHRT_MIN, INT_MIN, LONG_MIN}; + ULONG umax_value[3] = {USHRT_MAX, UINT_MAX, ULONG_MAX}, tmp; Shouldn't min_value be equal to 0?
How about changing the helper functions to have following prototypes: static LONG istream_internal_read_integer(istream *this, LONG min_value, LONG max_value); and static ULONG istream_internal_read_unsigned_integer(istream *this, ULONG max_value); I think the code will be nicer this way. Thanks, Piotr
On 02/08/16 14:32, Piotr Caban wrote:
On 08/02/16 13:37, Iván Matellanes wrote:
+static istream* istream_internal_read_unsigned_integer(istream *this, void *p, int size) +{ + /* size: 0 => short, 1 => int, 2 => long */ + ios *base = istream_get_ios(this); + char buffer[16]; + int num_base; + LONG min_value[3] = {SHRT_MIN, INT_MIN, LONG_MIN}; + ULONG umax_value[3] = {USHRT_MAX, UINT_MAX, ULONG_MAX}, tmp; Shouldn't min_value be equal to 0? These operators allow extracting negative values into unsigned variables, after performing the appropriate casting, e.g.: {type_uint, "-1", ..., /* 4294967295 */ 0, IOSTATE_eofbit, ...}, {type_uint, "-2", ..., /* 4294967294 */ 1, IOSTATE_eofbit, ...}, {type_uint, "-2147483648", ..., /* 2147483648 */ 2, IOSTATE_eofbit, ...}
How about changing the helper functions to have following prototypes: static LONG istream_internal_read_integer(istream *this, LONG min_value, LONG max_value); and static ULONG istream_internal_read_unsigned_integer(istream *this, ULONG max_value);
Yes, it looks better this way. Same for the floats helper. Thanks, Iván.
participants (2)
-
Iván Matellanes -
Piotr Caban