Sign in Join

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

Mailing lists / fpc-pascal / 2005-05

Re: ReadLn issues a warning

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Michael Van Canneyt
to Yiannis Dondos: could you please tell me if there is something wrong with the following code: program…
Yiannis Dondos wrote 24 lines
Hello everybody, could you please tell me if there is something wrong with the following code: program test1; var f: Text; i: Integer; s: ShortString; begin Assign (f, 'test.dat'); Reset (f); ReadLn (f, i); ReadLn (f, s); // Warning: Variable not initialized Close (f); end. FPC 1.9.8 on Linux issues a warning that FPC 1.0.10 never did. The question is why the string variable needs to be initialized?

It does not need to be. The warning is bogus. This is a bug.

Michael.

Yiannis Dondos

Hello everybody,

could you please tell me if there is something wrong with the following code:

program test1;
var
   f: Text;
   i: Integer;
   s: ShortString;
begin
     Assign (f, 'test.dat');
     Reset (f);
     ReadLn (f, i);
     ReadLn (f, s);  // Warning: Variable not initialized
     Close (f);
end.

FPC 1.9.8 on Linux issues a warning that FPC 1.0.10 never did. The question is why the string variable needs to be initialized? And if it does, then why the integer variable does not issue the same warning?

Thanks in advance,

Yannis.

Peter Vreman
to Michael Van Canneyt: It does not need to be. The warning is bogus. This is a bug. Michael.
you wrote 28 lines
On Sat, 14 May 2005, Yiannis Dondos wrote: > Hello everybody, > > could you please tell me if there is something wrong with the following > code: > > program test1; > > var > f: Text; > i: Integer; > s: ShortString; > > begin > Assign (f, 'test.dat'); > Reset (f); > > ReadLn (f, i); > ReadLn (f, s); // Warning: Variable not initialized > > Close (f); > end. > > FPC 1.9.8 on Linux issues a warning that FPC 1.0.10 never did. > The question is why the string variable needs to be initialized? It does not need to be. The warning is bogus. This is a bug.

The warning is a feature when you call your own made functions. For functions like readln() this shouldn't be triggered. Please report it as a bug.

Peter

Gerhard Scholz

Hello,

this is a general feature when using an uninitialized variable as a VAR parameter.

The compiler cannot know if the called routine needs the parameter values, or if the parameter is only used to return values back to the caller.

So, I think, a warning here could be helpful (in the case of READ(LN ) not of course, but in other cases).

Greetings

Gerhard

Date: Sat, 14 May 2005 12:12:50 +0200 (CEST)
From: Michael Van Canneyt
Subject: Re: [fpc-pascal] ReadLn issues a warning
To: FPC-Pascal users discussions
Message-ID:
Content-Type: TEXT/PLAIN; charset=US-ASCII

Yiannis Dondos wrote 24 lines
Hello everybody, could you please tell me if there is something wrong with the following code: program test1; var f: Text; i: Integer; s: ShortString; begin Assign (f, 'test.dat'); Reset (f); ReadLn (f, i); ReadLn (f, s); // Warning: Variable not initialized Close (f); end. FPC 1.9.8 on Linux issues a warning that FPC 1.0.10 never did. The question is why the string variable needs to be initialized?

It does not need to be. The warning is bogus. This is a bug.

Michael.

Peter Vreman
to Gerhard Scholz
Show quoted text 10 lines
Hello, this is a general feature when using an uninitialized variable as a VAR parameter. The compiler cannot know if the called routine needs the parameter values, or if the parameter is only used to return values back to the caller. So, I think, a warning here could be helpful (in the case of READ(LN ) not of course, but in other cases).

It is a known issue for Readln() and Str(). The routines need to be changed from 'var' to 'out'. But changing it short before the release was too risky.