Discussion:
Omit hint/warning for a fixed-size array
(too old to reply)
Ondrej Pokorny
2018-08-30 07:46:47 UTC
Permalink
Hello,

is there a way not to get a "Variable xyz does not seem to be
initialized" hint/warning for a fixed-size array?

program Project1;
uses Classes;
var
  Buffer: array[0..255] of Byte;
  FS: TFileStream;
begin
  // FillByte(Buffer, Length(Buffer), 0); // project1.lpr(9,18) Hint:
Variable "Buffer" does not seem to be initialized
  FS := TFileStream.Create('test.test', fmOpenRead);
  FS.Read(Buffer[0], Length(Buffer)); // << project1.lpr(11,11) Hint:
Variable "Buffer" does not seem to be initialized
end.

What is the correct code that doesn't emit any hint or warning?

Ondrej

_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mai
Michael Van Canneyt
2018-08-31 09:24:46 UTC
Permalink
Post by Ondrej Pokorny
Hello,
is there a way not to get a "Variable xyz does not seem to be
initialized" hint/warning for a fixed-size array?
program Project1;
uses Classes;
var
  Buffer: array[0..255] of Byte;
  FS: TFileStream;
begin
Variable "Buffer" does not seem to be initialized
  FS := TFileStream.Create('test.test', fmOpenRead);
Variable "Buffer" does not seem to be initialized
end.
What is the correct code that doesn't emit any hint or warning?
Type
TByteBuffer = array[0..255] of Byte;

Var
Buffer : TByteBuffer;

begin
Buffer:=Default(TByteBuffer);
end.

Michael.
Ondrej Pokorny
2018-08-31 10:36:22 UTC
Permalink
Post by Ondrej Pokorny
Hello,
is there a way not to get a "Variable xyz does not seem to be
initialized" hint/warning for a fixed-size array?
program Project1;
uses Classes;
var
  Buffer: array[0..255] of Byte;
  FS: TFileStream;
begin
Variable "Buffer" does not seem to be initialized
  FS := TFileStream.Create('test.test', fmOpenRead);
Variable "Buffer" does not seem to be initialized
end.
What is the correct code that doesn't emit any hint or warning?
Type
  TByteBuffer = array[0..255] of Byte;
Var
  Buffer : TByteBuffer;
begin
  Buffer:=Default(TByteBuffer);
end.
That was easy. Thank you!

Ondrej
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freep
w***@windstream.net
2018-08-31 12:32:57 UTC
Permalink
Post by Ondrej Pokorny
Hello,
is there a way not to get a "Variable xyz does not seem to be initialized"
hint/warning for a fixed-size array?
program Project1;
uses Classes;
var
Buffer: array[0..255] of Byte;
what about

Buffer: array[0..255] of Byte = [0];

would that or something similar work? i do similar in several of my programs but
i don't have any arrays in use in them...


eg:
MyMeanMotnStr : string = '';
MyMeanMotion : double = 0.0;
ModeDIAG : boolean = False;
obs_location : vector = (0,0,0,0);
sstringlen : longint = 0;


i know one solution has already been posted but thought of this one earlier when
i first read your post... i just delayed in writing this until now :/
--
NOTE: No off-list assistance is given without prior approval.
*Please keep mailing list traffic on the list unless*
*a signed and pre-paid contract is in effect with us.*
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.f
Michael Van Canneyt
2018-08-31 12:50:53 UTC
Permalink
Post by w***@windstream.net
Post by Ondrej Pokorny
Hello,
is there a way not to get a "Variable xyz does not seem to be initialized"
hint/warning for a fixed-size array?
program Project1;
uses Classes;
var
Buffer: array[0..255] of Byte;
what about
Buffer: array[0..255] of Byte = [0];
No, you would need to suppply the full amount of elements.

Michael.
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.fre
w***@windstream.net
2018-08-31 13:04:34 UTC
Permalink
Post by Michael Van Canneyt
Post by w***@windstream.net
Post by Ondrej Pokorny
Hello,
is there a way not to get a "Variable xyz does not seem to be initialized"
hint/warning for a fixed-size array?
program Project1;
uses Classes;
var
   Buffer: array[0..255] of Byte;
what about
    Buffer: array[0..255] of Byte = [0];
No, you would need to suppply the full amount of elements.
my statement "or similar" should cover that but yeah, i did think about that
aspect... it is a solution... just not a ""short hand" one ;)
--
NOTE: No off-list assistance is given without prior approval.
*Please keep mailing list traffic on the list unless*
*a signed and pre-paid contract is in effect with us.*
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.free
Thorsten Engler
2018-08-31 13:13:19 UTC
Permalink
Perhaps:

var
Buffer: array[0..255] of Byte = Default;

could be supported as shortcut for:

type
TByteBuffer = array[0..255] of Byte;
var
Buffer : TByteBuffer;
begin
Buffer := Default(TByteBuffer);
-----Original Message-----
Sent: Friday, 31 August 2018 23:05
Subject: Re: [fpc-devel] Omit hint/warning for a fixed-size array
Post by Michael Van Canneyt
Post by w***@windstream.net
Post by Ondrej Pokorny
Hello,
is there a way not to get a "Variable xyz does not seem to be
initialized"
Post by Michael Van Canneyt
Post by w***@windstream.net
Post by Ondrej Pokorny
hint/warning for a fixed-size array?
program Project1;
uses Classes;
var
Buffer: array[0..255] of Byte;
what about
Buffer: array[0..255] of Byte = [0];
No, you would need to suppply the full amount of elements.
my statement "or similar" should cover that but yeah, i did think
about that aspect... it is a solution... just not a ""short hand"
one ;)
--
NOTE: No off-list assistance is given without prior approval.
*Please keep mailing list traffic on the list unless*
*a signed and pre-paid contract is in effect with us.*
_______________________________________________
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listin

Loading...