Recent

Author Topic: null for a var parameter  (Read 5051 times)

mtanner

  • Sr. Member
  • ****
  • Posts: 287
Re: null for a var parameter
« Reply #15 on: July 16, 2020, 10:59:02 am »
Thanks for all the comments. My original "problem" was fairly trivial, just hoping for a way making code a little more intelligible. So in the end I think the simplest way is just to have dummy valiables declared at the top of the implementation, and used in calls where the actual variable value is not relevant. That way I at least do not have extraneous variable declaration within the main code, and it doesn't involve anything clever in the way of coding.

Thaddy

  • Hero Member
  • *****
  • Posts: 14210
  • Probably until I exterminate Putin.
Re: null for a var parameter
« Reply #16 on: July 16, 2020, 11:07:46 am »
Maybe trivial in your mind, but re-thinking your architecture usually leads to better code.
Trivial can always be demonstrated with an example.
Trivial is almost never trivial.
Specialize a type, not a var.

BrunoK

  • Sr. Member
  • ****
  • Posts: 452
  • Retired programmer
Re: null for a var parameter
« Reply #17 on: July 16, 2020, 11:35:50 am »
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. procedure SubCalc(X,Y,Z:double;var A1,A2,A3:double);
  4. begin
  5.   // ...
  6. end;
  7.  
  8. const
  9.   cDDBL: double = 0; // Dummy double
  10.  
  11. var
  12.   X,Y,Z,A1, A3: double;
  13.  
  14. begin
  15.   SubCalc(X,Y,X,A1,cDDBL,A3);
  16. end.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: null for a var parameter
« Reply #18 on: July 16, 2020, 12:20:33 pm »
Thanks for all the comments. My original "problem" was fairly trivial, just hoping for a way making code a little more intelligible. So in the end I think the simplest way is just to have dummy valiables declared at the top of the implementation, and used in calls where the actual variable value is not relevant. That way I at least do not have extraneous variable declaration within the main code, and it doesn't involve anything clever in the way of coding.

I would use local dummy variables, because the compiler can optimize these better than global ones. Especially if you declare your overloaded routines as inline.

Warfley

  • Hero Member
  • *****
  • Posts: 1499
Re: null for a var parameter
« Reply #19 on: July 16, 2020, 01:14:28 pm »
So in the end I think the simplest way is just to have dummy valiables declared at the top of the implementation, and used in calls where the actual variable value is not relevant.
How is that simpler than simply returing a record containing three fields? This way you don't need any dummy variables at all.

 

TinyPortal © 2005-2018