[GRASS-dev] Re: r.mapcal rand() strangeness
Ivan Shmakov
ivan at theory.asu.ru
Mon Feb 25 23:12:50 EST 2008
>>>>> Maciej Sieczka <tutey at o2.pl> writes:
[...]
>> I could change it to use strtol(), which sets errno to ERANGE on
>> overflow.
It may be better to check `*tailptr', like:
int
p_arg_long (const char *s, long *vp)
{
char *t;
long v;
if ((v = strtol (s, &t, 0)),
t == s || *t != '\0') {
/* . */
return -1;
}
if (vp != 0) *vp = v;
/* . */
return 0;
}
...
if (p_arg_long (str, &val) != 0) {
/* not a long integer */
}
Though `errno' may be used for finer diagnostics.
> Would that make r.mapcalc accept integers bigger than int32?
The sizes of the C types generally depend on the platform, but
for x86-based platforms I'm familiar with, sizeof (long) is 32.
It may make sense to use `long long' and strtoll () where
available.
[...]
More information about the grass-dev
mailing list