Jump to content
A.M. Hoornweg

Quickly zero all local variables?

Recommended Posts

Guest

for sue! 

at end, HE is always contested... :classic_cheerleader:

hug

Share this post


Link to post
1 hour ago, emailx45 said:

hey "genius" if dont like it, dont use!

Why would anybody use code that does nothing? You call a procedure passing parameters by value. Then that procedure modifies those parameters. You've basically done this:

 

procedure Foo(Value: Integer);
begin
  Value := 0;
end;

I don't think it takes a genius to see that this is pointless.

 

Furthermore, were your function able to do what you think it can, it's still useless. Who the heck is going to call a procedure passing a list of variables, to have that procedure set them to zero? You'll just set them to zero at the call site using the assignment operator. You really think people are going to write:

prcInitItPlease([lMyVarLocalThiProc, lMyOtherVarLocal]);

(which does not and cannot work as noted above)

 

rather than

 

lMyVarLocalThiProc := 0;
lMyOtherVarLocal := 0;

 

Honestly, this thread is mind boggling!

Edited by David Heffernan
  • Like 2

Share this post


Link to post
7 hours ago, Kas Ob. said:

with optimization enabled not all locals are stored on the stack, some are just reserved CPU registers

What is more, in some cases compiler can use the same register for several local variables. So, "all" local variables do not even exist at the beginning of procedure.

  • Like 1

Share this post


Link to post
33 minutes ago, emailx45 said:

JUST THE VALUE

It's passed by value in your procedure. The caller can't see the change. 

 

Also, the original concept would be something that would zeroise local vars without them needing to be listed.

 

Your code fails in every possible way to meet the requirements. And indeed any user defined function would fail, because the asker wants to have the compiler do it. 

 

 

Edited by David Heffernan
  • Like 2

Share this post


Link to post

I'm used to placing a procedure Init in any record so is simple to set defaults according to data types of records.

 

  PCompileArguments = ^TCompileArguments;
  TCompileArguments = record
    Mode: TCompileMode;
    Code: string;
    X: Extended;
    Y: Extended;
    Z: Extended;
    A: Extended;
    B: Extended;
    C: Extended;
    ToolPathMode: TToolPathMode;
    Line: Cardinal;
    FirstCmdId: Cardinal;
    LastLine: Cardinal;
    LastCmdId: Cardinal;
    procedure Assign(Source: PCompileArguments); overload;
    procedure Assign(Source: TCompileArguments); overload;
    procedure Init; overload;
    procedure Init(Mode: TCompileMode; const Code: string; X, Y, Z, A, B, C: Extended; ToolPathMode: TToolPathMode; Line, FirstCmdId, LastLine, LastCmdId: Cardinal); overload;
    function LoadFromMemento(Memento: IMemento): Boolean;
    function SaveToMemento(Memento: IMemento): Boolean;
  end;


 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×