Questions tagged [parameter-passing]

parameter-passing is the process of assigning values to the parameters of a function

Association of actual and formal parameters upon function call. See Parameter Passing and its methods. The most widely used parameter passing methods are:

  • call-by-value
  • call-by-reference
  • call-by-value-result
  • call-by-name
  • call-by-need
  • macro expansion.
8028 questions
95
votes
4 answers

Passing parameters to bash when executing a script fetched by curl

I know how to execute remote Bash scripts like this: curl http://example.com/script.sh | bash or bash < <( curl http://example.com/script.sh ) which give the same result. But what if I need to pass arguments to the bash script? It's possible when…
Daniel R
  • 1,515
  • 2
  • 12
  • 14
95
votes
10 answers

Can parameters be constant?

I'm looking for the C# equivalent of Java's final. Does it exist? Does C# have anything like the following: public Foo(final int bar); In the above example, bar is a read only variable and cannot be changed by Foo(). Is there any way to do this in…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
91
votes
5 answers

How to pass parameter on 'vagrant up' and have it in the scope of Vagrantfile?

I'm looking for a way to pass parameter to Chef cookbook like: $ vagrant up some_parameter And then use some_parameter inside one of the Chef cookbooks.
Wojciech Bednarski
  • 6,033
  • 9
  • 49
  • 73
90
votes
4 answers

How to pass 2D array (matrix) in a function in C?

I need to do this to persist operations on the matrix as well. Does that mean that it needs to be passed by reference? Will this suffice? void operate_on_matrix(char matrix[][20]);
Shweta
  • 5,198
  • 11
  • 44
  • 58
88
votes
6 answers

How to pass needed parameters to script in Powershell ISE?

See Title. I specified needed parameters in the head of a script: param ($G_ARCHIVE = $(throw "Need file to upload!"), $G_LOGFILE = $(throw "Need logfile!")) When I want to debug the script with Powershell ISE: how can I fill these…
eckes
  • 64,417
  • 29
  • 168
  • 201
82
votes
7 answers

Invoke a second script with arguments from a script

I have a script that reads a configuration file that results in a set of name value pairs that I would like to pass as arguments to a function in a second PowerShell script. I do not know what parameters will be placed in this configuration file at…
81
votes
8 answers

C++ view types: pass by const& or by value?

This came up in a code review discussion recently, but without a satisfactory conclusion. The types in question are analogues to the C++ string_view TS. They are simple non-owning wrappers around a pointer and a length, decorated with some custom…
acm
  • 12,183
  • 5
  • 39
  • 68
79
votes
5 answers

How to pass a switch parameter to another PowerShell script?

I have two PowerShell scripts, which have switch parameters: compile-tool1.ps1: [CmdletBinding()] param( [switch]$VHDL2008 ) Write-Host "VHDL-2008 is enabled: $VHDL2008" compile.ps1: [CmdletBinding()] param( [switch]$VHDL2008 ) if (-not…
Paebbels
  • 15,573
  • 13
  • 70
  • 139
74
votes
9 answers

Pass array to MySQL stored routine

I need to pass an array of strings as parameter to a MySQL stored routine. The array could be long and its number of elements is not fixed. I then want to put the string values into an in-memory table with one column, so I can work with the data. I…
Gruber
  • 4,478
  • 6
  • 47
  • 74
74
votes
2 answers

What do * (single star) and / (slash) do as independent parameters?

In the following function definition, what do the * and / account for? def func(self, param1, param2, /, param3, *, param4, param5): print(param1, param2, param3, param4, param5) NOTE: Not to mistake with the single|double asterisks in *args |…
ibarrond
  • 6,617
  • 4
  • 26
  • 45
74
votes
9 answers

Can you pass-by-reference in R?

Can you pass by reference with "R" ? for example, in the following code: setClass("MyClass", representation( name="character" )) instance1 <-new("MyClass",name="Hello1") instance2 <-new("MyClass",name="Hello2") array =…
Pierre
  • 34,472
  • 31
  • 113
  • 192
72
votes
3 answers

Passing variables, creating instances, self, The mechanics and usage of classes: need explanation

I just rewrote a working program into functions in a class and everything messed up. First, in the __init__ section of the class I declared a bunch of variables with self.variable=something. Should I be able to access/modify these variables in every…
Baf
  • 2,041
  • 3
  • 16
  • 10
70
votes
5 answers

How can I use "Dependency Injection" in simple php functions, and should I bother?

I hear people talking about dependency injection and the benefit of it all the time, but I don't really understand it. I'm wondering if it's a solution to the "I pass database connections as arguments all the time" problem. I tried reading…
Kzqai
  • 22,588
  • 25
  • 105
  • 137
70
votes
4 answers

MSBuild passing parameters to CallTarget

I'm trying to make a reusable target in my MSBuild file so I can call it multiple times with different parameters. I've got a skeleton like this: