[Info-vax] Significance of 2020 / 2021 date
Arne Vajhøj
arne at vajhoej.dk
Sat Jan 9 10:40:53 EST 2021
On 1/9/2021 7:50 AM, Chris wrote:
> On 01/09/21 12:35, Andy Burns wrote:
>> Chris wrote:
>>> issinoho wrote:
>>>> if (atoi (date_string + 5)> 2020)
>>>
>>> That code is type unsafe for starters. atoi() requires an ascii string,
>>> but you are trying to add 5 decimal to an ascii string ?.
>>
>> atoi requires a *pointer* to an asciiz string, presumably in this case
>> the format is something like DDMMMYYYY, so that the +5 starts the
>> decimal conversion from the address of the first Y.
>
> Ok, but I would not be doing pointer arithmetic inside an ancient
> library function such as atoi(). Expecting the compiler to a be a
> mindreader etc.
It does not need to be a mind reader. It just needs to
follow the C standard.
If you have a char* and add an int then you get another
char* and the expression will be evaluated before the call
and char* is what atoi expects.
It may not be robust code and it may not be super readable
code, but it should not be a problem for the compiler to
do what it is being told.
Arne
More information about the Info-vax
mailing list