[fpc-pascal] How to eliminate specific hint (was: how to initialize a SearchRec var?)

Pierre Free Pascal pierre at freepascal.org
Fri Jan 3 11:05:06 CET 2014


> // prevents the compiler hint about not initialized variables
> procedure dcpFillChar(out x; count: SizeInt; Value: Byte);
> begin
>   {$HINTS OFF}
>   FillChar(x, count, value);
>   {$HINTS ON}
> end;
>
>
> begin
>
>    dcpFillchar(dirinfo,sizeof(dirinfo),$00);
>    FindFirst(pattern,AnyFile,dirinfo);
>    findclose(dirinfo);
> end.
> ----8<-------------8<-------------8<-------------8<-------------8<----
I would suggest to use the following sequence instead:
=== code begin ===
{$push}
{$hints off}
// whatever
{$pop}
=== code end ===

  The is a more specific way to remove a given hint:

Use -vq option to get the numeric value of the message:

E:\pas\test>ppc386 -vhq tsearchrec.pas
Hint: (11030) Start of reading config file
e:\pas\fpc-2.7.1\bin\i386-win32\fpc.cfg
Hint: (11031) End of reading config file
e:\pas\fpc-2.7.1\bin\i386-win32\fpc.cfg
tsearchrec.pas(13,20) Hint: (5058) Variable "dirinfo" does not seem to be
initialized

Disable that specific message by using -vm option:

E:\pas\test>ppc386 -vh -vm5058 tsearchrec.pas
Hint: Start of reading config file e:\pas\fpc-2.7.1\bin\i386-win32\fpc.cfg
Hint: End of reading config file e:\pas\fpc-2.7.1\bin\i386-win32\fpc.cfg

Magic, isn't it?


Pierre Muller



More information about the fpc-pascal mailing list