"Local variable does not seem to be initialized" for move, fillchar - won't fix? lazarus / 62-General ---------------------------------------------------------------------- Artlav · 2017-03-31 19:03 So, there is many a line in the code to the effect of Code: [Select]fillchar(lambda[0],32,0); Lazarus would give out a warning for it: Code: [Select]ecc.pas(146,11) Hint: Local variable "lambda" does not seem to be initialized It's a useful warning in many cases, so i don't want to disable it completely. I also don't want to be putting {%H-} everywhere. So i edited the RTL of FPC, to redefine these functions like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure FillChar(out x;count:SizeInt;Value:Byte);Procedure FillChar(out x;count:SizeInt;Value:Boolean);Procedure FillChar(out x;count:SizeInt;Value:Char); This got rid of the warning, and for a time all was well. However, i just tried to rebuild Lazarus, and there were a lot of weird crashes. Rolling back that fix restored it's functionality, and left me with a profound feeling of WTF. So, WTF? Why do these generate a warning, and why making an output-only-by- definition parameter output-only breaks things? ---------------------------------------------------------------------- Jonas Maebe · 2017-03-31 19:05 http://lists.freepascal.org/pipermail/fpc- devel/2009-November/018527.html ---------------------------------------------------------------------- Artlav · 2017-03-31 19:15 Quote from: Graeme GeldenhuysNo, that is not possible. I once tried to change move and fillchar to use "out" parameters instead of "var" parameters, and the result was all sorts of crashes. The reason is that "out" has special semantics for reference counted types (they are finalized at the *caller* side), and move/fillchar are sometimes used to zero uninitialised data (so if the run time then tries to finalise garbage, you get crashes). I see, thanks. That's the sort of thing i suspected might be happening. Ok, so why wasn't this fixed some other way since then? I.e. add a marker like {%H-}, only to be placed at the definition, telling the compiler to ignore a warning if it's about the definition with a marker? ---------------------------------------------------------------------- howardpc · 2017-03-31 20:12 Quote from: Artlav on March 31, 2017, 09:15:06 pmOk, so why wasn't this fixed some other way since then? I.e. add a marker like {%H-}, only to be placed at the definition, telling the compiler to ignore a warning if it's about the definition with a marker? {%H-} is a Lazarus IDE directive. It is effective only within the Lazarus IDE, and when using the IDE to do builds and compiles. But I guess you could devise a macro to automatically insert this directive in FillChar code. FPC knows nothing of such comments and does not use them, and correctly ignores them. ---------------------------------------------------------------------- Thaddy · 2017-04-01 04:26 The way to hide specific messages locally is also documented in the users and programmers manual. An example would be Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program testmt; procedure test;var  Buffer: array[0..9] of char;{$push}{$warn 5057 off}  // hide warning var not initializedbegin  fillchar(buffer,32,10)end;{$pop} beginend.$push and $pop save and restore the currently active directives/environment. Globally you can add the above w.o push/pop or use -vm5057 as option http://freepascal.org/docs- html/current/user/usersu13.html#x36-430005.1.2 http://freepascal.org/docs- html/current/prog/progsu80.html#x87-860001.2.80 Note: the push and pop are here around the begin end block of the procedure, but in fact you can use it inside the procedure for defined blocks as well. Since this procedure has no blocks, it surrounds the whole procedure. It doesn't work on statements alone. Unless that statement implies a block. (while, case, if then) Note2: The easiest way to obtain the error number is to compile with  -vwhnlq which will give you line number + error code for warnings,hints and notes. I am not aware of a standard unit with more readable defines for these numbers. ---------------------------------------------------------------------- creaothceann · 2017-04-01 07:42 I did it in my code like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure MemClear(out DATA;  const ByteCount : u64);beginSystem.FillChar((@DATA)^, ByteCount, 0);end;  function MemCompare(p1, p2 : pointer;  ByteCount : u64) : bool;var p1_08 : ^u8 absolute p1;    p1_16 : ^u16 absolute p1;    p1_32 : ^u32 absolute p1;    p1_64 : ^u64 absolute p1;var p2_08 : ^u8 absolute p2;    p2_16 : ^u16 absolute p2;    p2_32 : ^u32 absolute p2;    p2_64 : ^u64 absolute p2;beginwhile (ByteCount >= 8) do begin  if (p1_64^ <> p2_64^) then exit(False);  Inc(p1_64);  Inc(p2_64);  Dec(ByteCount, 8);  end;while (ByteCount >= 4) do begin  if (p1_32^ <> p2_32^) then exit(False);  Inc(p1_32);  Inc(p2_32);  Dec(ByteCount, 4);  end;while (ByteCount >= 2) do begin  if (p1_16^ <> p2_16^) then exit(False);  Inc(p1_16);  Inc(p2_16);  Dec(ByteCount, 2);  end;while (ByteCount >= 1) do begin  if (p1_08^ <> p2_08^) then exit(False);  Inc(p1_08);  Inc(p2_08);  Dec(ByteCount   );  end;Result := True;end;  procedure MemCopy(const SRC;  out DEST;  const ByteCount : u64);beginSystem.Move((@SRC)^, (@DEST)^, ByteCount);end; (u64 = QWord, bool = Boolean) ---------------------------------------------------------------------- Thaddy · 2017-04-06 14:44 Look at the date..... ---------------------------------------------------------------------- Artlav · 2017-04-06 20:11 Quote from: Thaddy on April 01, 2017, 06:26:53 amThe way to hide specific messages locally is also documented in the users and programmers manual.Yes, this does work. The problem is not that it's impossible to do, it's that every way to do it that exists now is quite ugly. I want a way to cut such obviously invalid warnings at the source, instead of slapping tentacles forever. ---------------------------------------------------------------------- BeniBela · 2017-04-06 20:50 You can use Code: [Select]procedure fillptr(p: pointer; size: integer; v: integer = 0); inline; begin   fillchar(p^, size, v); end; ---------------------------------------------------------------------- Thaddy · 2017-04-07 05:56 And for smaller sizes you can of course simply initialize at declaration: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure test;var  Buffer: array[0..9] of byte =(32,32,32,32,32,32,32,32,32,32);beginend; ---------------------------------------------------------------------- creaothceann · 2017-04-07 16:18 It's actually enough to set only one item of an array (or one field of a record) to make the message go away. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Test;var buffer : array[0..9] of byte;beginbuffer[0] := 0;// ...end; ---------------------------------------------------------------------- Thaddy · 2017-04-07 16:31 Quote from: creaothceann on April 07, 2017, 06:18:14 pmIt's actually enough to set only one item of an array (or one field of a record) to make the message go away. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Test;var buffer : array[0..9] of byte;beginbuffer[0] := 0;// ...end;And that... is conceptually wrong.. It is rather strange that the compiler doesn't warn there, because the array is NOT initialized. Just one element is. Actually it is much worse than the original bogus warning. Can get you into a lot of trouble. Don't try that at home.. You may well be introducing bugs in other cases than to prevent the not initialized warning when it is initialized by fillchar. ---------------------------------------------------------------------- creaothceann · 2017-04-11 00:23 In FPC's defense, it's probably unreasonable to let the compiler keep track of every single byte of an array/record... I could easily declare and use a 30GB array in RAM (on my machine), but not if the compiler tries to keep track of it (without some clever logic). ---------------------------------------------------------------------- del · 2021-02-15 22:48 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i buff: array[1..BUF_SIZE] of byte; begin buff[1] := 0; I went this route myself. (BUF_SIZE is 2048). The warnings are just to draw your attention to things. The compiler just wants to feel comfortable that you're aware of the situation. That's why the compiler warns you about "implicit" conversions. So instead of "muting" the compiler, I signal to the compiler that I'm aware of the situation. And the compiler calms down. ---------------------------------------------------------------------- trev · 2021-02-15 23:53 Quote from: del on February 15, 2021, 11:48:50 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  buff[1] := 0; The first element of the array is 0 not 1. See Thaddy's warning above about doing this: the cure may be worse than the disease. Personally I'd use initialize: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure foo;var  buffer : array[0..9] of byte;begin  initialize(buffer, length(buffer)); ... Finally, you're replying to a 4 year old thread. ---------------------------------------------------------------------- del · 2021-02-16 04:45 Quote from: trev on February 16, 2021, 12:53:23 amQuote from: del on February 15, 2021, 11:48:50 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  buff[1] := 0; The first element of the array is 0 not 1. See Thaddy's warning above about doing this: the cure may be worse than the disease. Personally I'd use initialize: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure foo;var  buffer : array[0..9] of byte;begin  initialize(buffer, length(buffer)); ... Finally, you're replying to a 4 year old thread. I didn't need the thread until now. And I didn't find a good answer until now. When I tried "0" as the first element I got a range error. Now the next time somebody comes here they'll see a good answer. Thanks. ---------------------------------------------------------------------- ccrause · 2021-02-16 07:02 Quote from: trev on February 16, 2021, 12:53:23 amQuote from: del on February 15, 2021, 11:48:50 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  buff[1] := 0; The first element of the array is 0 not 1. In del's example the array was defined to start at 1: Quote from: del on February 15, 2021, 11:48:50 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i buff: array[1..BUF_SIZE] of byte; ---------------------------------------------------------------------- del · 2021-02-16 11:24 Yeah it's from some example I found (maybe here) for grabbing the output of a program you're running with TProcess.