[fpc-pascal] Checking the validity of Format and friends at compile-time
Michalis Kamburelis
michalis.kambi at gmail.com
Wed Oct 5 19:47:37 CEST 2016
2016-10-05 9:00 GMT+02:00 Maciej Izak <hnb.code at gmail.com>:
>
> 2016-10-05 4:32 GMT+02:00 Michalis Kamburelis <michalis.kambi at gmail.com>:
>>
>> For example, the call
>>
>> Format('%s', [123])
>
>
> I have a small hint (instead of answer). We have in mORMot / NewPascal in
> SynCommons module nice function which works perfect in most of cases:
>
> FormatUTF8('%', [123], []); // same string '%' works for both: integer and
> string values
> FormatUTF8('%', ['123'], []);
>
That's a cool improvement. No need to write the type, so one less
thing that can go wrong:) I seldom use non-standard formats anyway
(like %g instead of %f for floats).
Still, you can use an invalid number of arguments for FormatUTF8. So
you still have this uncomfortable feeling that "it's only checked at
runtime, while it could be checked earlier at lint / compile phase" :)
I'm leaning toward implementing a simple pascal-lint tool myself,
using the fcl-passrc. But to make it really useful on my real code,
I'll need some fixes to fcl-passrc first:)
Regards,
Michalis
More information about the fpc-pascal
mailing list