Questions tagged [argument-passing]

Argument-passing may refer to two different things: (1) the process of providing a program being started with some initial pieces of information (the arguments) on its command line; (2) the process of providing the initial values (the arguments) for the parameters of a function when it is called.

777 questions
6
votes
6 answers

Array as a parameter

I have created an array: CString* pstrArray = new CString[nMySize]; Now how can I pass it to a function to be filled up? What is the actual parameter? void FillThisArray(what goes here?) { }
Sunscreen
  • 3,452
  • 8
  • 34
  • 40
6
votes
1 answer

Magento custom admin module is blank

I've create a custom admin module but i can't put a content in it, it always is blank i'm trying with a simple code for test, but nothing seem to work public function indexAction() { $this->loadLayout(); …
Castro Roy
  • 7,623
  • 13
  • 63
  • 97
6
votes
1 answer

Pass $@ to a function in a shellscript

Problem description In a shell script, I want to iterate over all command line arguments ("$@") from inside a function. However, inside a function, $@ refers to the function arguments, not the command line arguments. I tried passing the arguments to…
jornane
  • 1,397
  • 10
  • 27
6
votes
5 answers

How can multiple variables be passed to a function cleanly in C?

I am working on an embedded system that has different output capabilities (digital out, serial, analog, etc). I am trying to figure out a clean way to pass many of the variables that will control those functions. I don't need to pass ALL of them…
aquanar
  • 1,531
  • 2
  • 11
  • 8
6
votes
3 answers

How to write lambda function with arguments? c++

I want to call a method (for this example std::thread constructor) with lambda function, passing int value: int a=10; std::thread _testThread = thread([a](int _a){ //do stuff using a or _a ? }); _testThread.detach(); I don't know how to…
Dainius Kreivys
  • 525
  • 2
  • 8
  • 19
6
votes
2 answers

Why do argument lists in certain Cocoa methods end with a nil?

Why do argument list in some methods end with nil? I have noticed this particularly in the collection classes, for example NSSet: mySet = [NSSet setWithObjects:someData, aValue, aString, nil]; and NSArray: NSArray *objects = [NSArray…
6
votes
1 answer

Argument conversion: (normal) pointer to void pointer, cast needed?

When assigning to or from a void-pointer no cast is needed (C99 §6.3.2.2 sub 1 / §6.5.16.1 sub 1). Is this also true when passing a (for example int-)pointer to a function that expects a void-pointer? For example: void foo(void * p){ // Do…
Kninnug
  • 7,992
  • 1
  • 30
  • 42
6
votes
2 answers

Wrapper for a Command Line Tool in C#

Using MSDN I got the class to write a wrapper for my command line tool. I now am facing a problem, if I execute the exe through the command line with arguments, it works perfect without any errors. But when I try to pass the arguments from the…
6
votes
5 answers

Hashes vs. Multiple Params?

It is very common in Ruby to see methods that receive a hash of parameters instead of just passing the parameters to the method. My question is - when do you use parameters for your method and when do you use a parameters hash? Is it right to say…
Shay Friedman
  • 4,808
  • 5
  • 35
  • 51
6
votes
3 answers

Why doesn't Google Guava Preconditions's checkArgument return a value?

I really love how guava library allows simple one-liners for checking for null: public void methodWithNullCheck(String couldBeNull) { String definitelyNotNull = checkNotNull(couldBeNull); //... } sadly, for simple argument check you need at…
Petro Semeniuk
  • 6,970
  • 10
  • 42
  • 65
6
votes
5 answers

Java vs C++ for passing arguments

Ive started to get my head in a bit of a mix regarding how Java and C++ pass arguments. Is this correct: Java passes using call by value, but the value is actually the reference (not the actual data/object). So a copy of the address is made? C++ by…
intrigued_66
  • 16,082
  • 51
  • 118
  • 189
5
votes
4 answers

int foo (int argc, ...) vs int foo() vs int foo(void) in C

So today I figured (for the first time admittedly) that int foo() is in fact different from int foo(void) in that the first one allows any number of inputs and the second one allows zero. Does int foo() simply ignore any given inputs? If so, what's…
mmirzadeh
  • 6,893
  • 8
  • 36
  • 47
5
votes
7 answers

What are the differences between parameter definitions as (type& name), and (type* name)?

A very basic question, but still, it would be good to hear from C++ gurus out there. There are two rather similar ways to declare by-reference parameters in C++. 1) Using "asterisk": void DoOne(std::wstring* iData); 2) Using "ampersand": void…
Ignas Limanauskas
  • 2,436
  • 7
  • 28
  • 32
5
votes
3 answers

Smart way to pass arguments in Fortran 90

I am a Fortran novice. I am trying to write a subroutine that will take in four arguments from the main program, and then outputs to the main program an array that involves the four arguments that were originally passed in. What is a good/smart…
Andrew
  • 1,499
  • 9
  • 25
  • 37
5
votes
2 answers

c# Generics: Passing List to a method that expects a List

I've had my first foray into generics, and understand them a little bit. I have a method intended to accept two lists of any object, match them various ways and return the matched/unmatched objects (the stuff inside the method probably isn't key…
Glinkot
  • 2,924
  • 10
  • 42
  • 67