pereges said:
After conversion, if I check a against SIZE_MAX and SIZE_MIN..probably
that can help.
As has already been pointed out, there is no SIZE_MIN; it's just 0.
I think that SIZE_MAX is new in C99. If so, you can use (size_t)-1,
which is guaranteed to be the largest value of type size_t.
In C90, size_t can't be any bigger than unsigned long, though it may
be smaller. You can use strtoul() to get an unsigned long value,
compare the result against SIZE_MAX, and assign it to a size_t object.
(Note: no cast is needed or recommended for this assignment.)
In C99, size_t can be bigger than unsigned long; it can even, in
theory, be bigger than unsigned long long. To be completely safe, you
can use strtoumax(). And for compatibility with both C90 and C99, you
can check the value of __STDC_VERSION__, writing separate code for C90
and C99.
It's likely that you don't need absolute 100% portability, and that
restricting yourself to values within the range of unsigned long is
good enough for your purposes; if so, you can write straight
C90-compatible code, at some small risk of rejecting valid size_t
values greater than 2**31-1 (more precisely, greater than ULONG_MAX).
In fact, the C99 standard recommends (but does not insist) that size_t
be no wider than unsigned long.