Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-04

Initializing a record-type variable to get rid of the false-positive compiler hint

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bihar Anwar

I still need compiler hint generated by FPC at compiling (I don't want to turn it off), but the hint sometime disturbs me because it's a false-postive detection.

Supposing I have a record-type variable, could someone here tell me how to initialize it properly so that FPC could notice the initialization, since the FillByte() and FillChar() way do not cause FPC aware of it?

This is part of my code:

var
  oSearchOptions: TSearchFileOptions;
FillByte(oSearchOptions, SizeOf(oSearchOptions), 0);

I got this compiler hint when compiling:
Variable "oSearchOptions" does not seem to be initialized.

Thanks for any comments.

Reply by email

José Mejuto
to Bihar Anwar

Hello FPC-Pascal,

Wednesday, April 14, 2010, 5:13:51 PM, you wrote:

BA> Supposing I have a record-type variable, could someone here BA> tell me how to initialize it properly so that FPC could notice the BA> initialization, since the FillByte() and FillChar() way do not BA> cause FPC aware of it?

I'm using:

procedure InitRecord(out Rec; const ASize: SizeUint);
begin
{$PUSH}
{$HINTS OFF}
  FillByte(Rec,ASize,0);
{$POP}
end;

Unfortunatly it can not be inlined :( due the formal parameter.

Best regards, José

Reply by email

Bihar Anwar
to José Mejuto

Thanks for your reply José, but what is the philosophy behind the solution? and What are the reasons for $PUSH and $POP? Also, I tried to remove the $HINTS directive, and it worked fine without it. Could you explain this?

Earlier message 25 lines
----- Original Message ---- From: José Mejuto Subject: Re: [fpc-pascal] Initializing a record-type variable to get rid of the false-positive compiler hint BA> Supposing I have a record-type variable, could someone here BA> tell me how to initialize it properly so that FPC could notice the BA> initialization, since the FillByte() and FillChar() way do not BA> cause FPC aware of it? I'm using: procedure InitRecord(out Rec; const ASize: SizeUint); begin {$PUSH} {$HINTS OFF} FillByte(Rec,ASize,0); {$POP} end; Unfortunatly it can not be inlined :( due the formal parameter. -- Best regards, José

Reply by email

Bihar Anwar
to Bart

Thanks Bart, forget my silly comments before, you did it cleverly.

Earlier message 11 lines
----- Original Message ---- From: Bart To: FPC-Pascal users discussions Sent: Thu, April 15, 2010 10:02:33 PM Subject: Re: [fpc-pascal] Initializing a record-type variable to get rid of the false-positive compiler hint > FillByte(oSearchOptions, SizeOf(oSearchOptions), 0); oSearchOptions := []; //It's an empty set Bart

Reply by email

José Mejuto
to Bihar Anwar: Thanks for your reply José, but what is the philosophy behind the solution? and What are…

Hello FPC-Pascal,

Thursday, April 15, 2010, 6:43:41 AM, you wrote:

BA> Thanks for your reply José, but what is the philosophy behind BA> the solution? and What are the reasons for $PUSH and $POP? Also, I BA> tried to remove the $HINTS directive, and it worked fine without BA> it. Could you explain this?

Rec parameter is qualified as "out" so, the enter values is non-important and the compiler will not generate the "non initialized" hint.

The $PUSH pushes in fpc stack the current settings about hints, warnings, alignement, etc, then I change the hints to off, because FillByte could produce (not sure with formal parameter) the hint message and then $POP restores previous settings about hints and other directives.

Best regards, José

Reply by email

Bihar Anwar
to José Mejuto

Thank you very much Jose, that's a detail explanation. Forget my wrong observation before.

Earlier message 29 lines
----- Original Message ---- From: José Mejuto To: FPC-Pascal users discussions Sent: Thu, April 15, 2010 10:11:03 PM Subject: Re[2]: [fpc-pascal] Initializing a record-type variable to get rid of the false-positive compiler hint Hello FPC-Pascal, Thursday, April 15, 2010, 6:43:41 AM, you wrote: BA> Thanks for your reply José, but what is the philosophy behind BA> the solution? and What are the reasons for $PUSH and $POP? Also, I BA> tried to remove the $HINTS directive, and it worked fine without BA> it. Could you explain this? Rec parameter is qualified as "out" so, the enter values is non-important and the compiler will not generate the "non initialized" hint. The $PUSH pushes in fpc stack the current settings about hints, warnings, alignement, etc, then I change the hints to off, because FillByte could produce (not sure with formal parameter) the hint message and then $POP restores previous settings about hints and other directives. -- Best regards, José

Reply by email