[Info-vax] Significance of 2020 / 2021 date
Dave Froble
davef at tsoft-inc.com
Sat Jan 9 21:15:39 EST 2021
On 1/9/2021 6:33 PM, Bill Gunshannon wrote:
> On 1/9/21 10:43 AM, 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
>>
>
>
> I agree. I misunderstood. Probably because I was trying to figure out
> what they wanted done rather than what t hey were doing. I can safely
> say I would (and to the best of my knowledge never have) do anything
> like that.
>
> bill
>
Playing around with pointers isn't the worst thing one could do. Code
like that without adequate comments deserves tar, feathers, and a rail.
--
David Froble Tel: 724-529-0450
Dave Froble Enterprises, Inc. E-Mail: davef at tsoft-inc.com
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA 15486
More information about the Info-vax
mailing list