[Info-vax] Significance of 2020 / 2021 date
Chris
xxx.syseng.yyy at gfsys.co.uk
Sat Jan 9 19:28:30 EST 2021
On 01/09/21 22:20, 1tim.... at gmail.com wrote:
> On Saturday, January 9, 2021 at 8:43:09 AM UTC-7, Arne Vajhøj wrote:
>> On 1/9/2021 8:38 AM, Bill Gunshannon wrote:
>>> On 1/9/21 8:27 AM, Bill Gunshannon wrote:
>>>> On 1/9/21 7:35 AM, 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.
>>>>>
>>>>
>>>> Am I the only one who things this was fat fingered and the example
>>>> should really be: if ((atoi (date_string) + 5)> 2020)
>> That code makes little sense.
>>
>> The original code as already noted do a skip of DDMMM.
>>>> I would have expected the original to generate an error at compile
>>>> time.
>>>
>>> OK, it made me curious enough that I tried a few examples. Apparently
>>> the compiler (at least gcc) doesn't really care what you throw at the
>>> call to atoi(). Interesting to say the least.
>> char* + int is char*. atoi expects char*. Why should it complain?
>>
>> Arne
>
>
> You're right! I just re-read it. duh! offset the date string start by 5 chars, do the atoi for the last part of the string and do the compare.
>
> I'm embarrassed :-)
No reason, as while it may be legal syntax, if you are reviewing for
maintenance, that interrupts the mental flow, pause for a second
while you decode what it means. No excuse for such lazy style, decades
ago or not. Wouldn't last 5 minutes in industry with regular code
reviews. Cryptic hard coded constants in the code as well !.
Ongoing maintenance can take up far more resources that the whole
original project cost, so needs to be done right from the start...
Chris
>
> I was reading it as add 5 to the value of the date string and compare. Not offset from the start of the string.
More information about the Info-vax
mailing list