Pascal Viandier wrote:
Is there a gpc directive that can issue a message and then abort the compilation? I tried {$M ...} but it does not stop the compilation process.
My goal is to prohibit the use of FillChar() in our code by stopping the compilation when the compiler finds one.
{$error foo}
The compilation will continue, like after most errors, but return with an error at the end. However, the above does not work as a macro such as "{$define foo {$error foo}}" since nested compiler directives are not (yet) allowed.
I used a macro that redefines FillChar(a,b,c); as {$M ERROR: Fillchar use is not allowed!} but this does not seem sufficient to prevent its usage and its destructive effect on strings :-(
Destructive only if used carelessly. When used in a proper way (possibly the only one originally intended), it's fine:
FillChar (s[a], b, c); { provided (a >= 1) and (a + b - 1 <= Length (s)) }
(It's destructive if you do "FillChar (s, ...)". But even with BP strings that's usually at least pointless, since the first "char" is the length byte. If you fill with 0, you set the length to 0, and so the string to '', but you get the same thing more efficiently (even in BP) and much more portably by just doing "s := ''". Unless in very special circumstances where you also need all characters to be Chr(0), such as perhaps when you want to write the string to a binary file and be sure it contains no dummy data.)
If there is no such compiler directive, any other suggestion is welcome.
{$disable-predefined-identifier=FillChar}
Frank