Aborting compilation

Frank Heckenbach ih8mj at fjf.gnu.de
Thu Apr 30 20:52:05 CEST 2009


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

-- 
Frank Heckenbach, f.heckenbach at fh-soft.de, http://fjf.gnu.de/, 7977168E
GPC To-Do list, latest features, fixed bugs:
http://www.gnu-pascal.de/todo.html
GPC download signing key: ACB3 79B2 7EB2 B7A7 EFDE  D101 CD02 4C9D 0FE0 E5E8





More information about the Gpc mailing list