Sign in Join

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

Mailing lists / fpc-devel / 2018-08

Omit hint/warning for a fixed-size array

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

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
   // 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

Reply by email

Michael Van Canneyt
to Ondrej Pokorny
Ondrej Pokorny wrote 19 lines
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?
Type
   TByteBuffer = array[0..255] of Byte;
Var
   Buffer : TByteBuffer;
begin
   Buffer:=Default(TByteBuffer);
end.

Michael.

Reply by email

Ondrej Pokorny
to Michael Van Canneyt
Michael Van Canneyt wrote 30 lines
On Thu, 30 Aug 2018, Ondrej Pokorny wrote: > 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? Type   TByteBuffer = array[0..255] of Byte; Var   Buffer : TByteBuffer; begin   Buffer:=Default(TByteBuffer); end.

That was easy. Thank you!

Ondrej

Reply by email

Unknown author
to Ondrej Pokorny: is there a way not to get a "Variable xyz does not seem to be initialized" hint/warning…
Ondrej Pokorny wrote 9 lines
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.*

Reply by email

Michael Van Canneyt
to Unknown author
Show quoted text 14 lines
On 08/30/2018 03:46 AM, Ondrej Pokorny wrote: > 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.

Reply by email

Unknown author
to Michael Van Canneyt
Michael Van Canneyt wrote 17 lines
On Fri, 31 Aug 2018, wrote: > On 08/30/2018 03:46 AM, Ondrej Pokorny wrote: >> 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.*

Reply by email

Thorsten Engler
to Unknown author

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);
Show quoted text 40 lines
-----Original Message----- From: fpc-devel On Behalf Of Sent: Friday, 31 August 2018 23:05 To: Subject: Re: [fpc-devel] Omit hint/warning for a fixed-size array On 08/31/2018 08:50 AM, Michael Van Canneyt wrote: > On Fri, 31 Aug 2018, wrote: >> On 08/30/2018 03:46 AM, Ondrej Pokorny wrote: >>> 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 - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email