Recent

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

mtanner

  • Full Member
  • ***
  • Posts: 241
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: 10475
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.
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

BrunoK

  • Sr. Member
  • ****
  • Posts: 262
  • 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: 2138
  • 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

  • Sr. Member
  • ****
  • Posts: 303
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