pass-by-reference

F#: How to write the classic swap function?

In C# the classic swap function is: void swap (ref int a, ref int b){ int temp = a; a = b; b = temp; } int a = 5; int b = 10; swap( ref a, ref b); How would I write that with F#? (Note, I do not want the functional equivalent. I actually need pass by reference semantics.) ...

C#: What is the use of "ref" for Reference-type variables?

I understand that if I pass a value-type (int, struct etc...) as a parameter (without the ref keyword), a copy of that variable is passed to the method, but if I use the ref keyword a reference to that variable is passed, not a new one. But with reference-types, like classes, even without the ref keyword a reference is passed to the met...

Why does perl "hash of lists" do this?

I have a hash of lists that is not getting populated. I checked that the block at the end that adds to the hash is in fact being called on input. It should either add a singleton list if the key doesn't exist, or else push to the back of the list (referenced under the right key) if it does. I understand that the GOTO is ugly, but I've ...

Python: How do I pass a variable by reference?

The Python documentation seems unclear about whether parameters are passed by reference or value, and the following code produces the unchanged value 'Original' class PassByReference: def __init__(self): self.variable = 'Original' self.Change(self.variable) print self.variable def Change(self, var): var = 'C...

How to avoid explicitly calling a constructor when passing temporary object by reference in C++?

Let's say I have a class: class String { public: String(char *str); }; And two functions: void DoSomethingByVal(String Str); void DoSomethingByRef(String &Str); If I call DoSomethingByVal like this: DoSomethingByVal("My string"); the compiler figures out that it should create a temporary String object and call the char* con...

different by ref question using a simple =

I have a variant on the by ref question. I know all about calling with the ref or our parameters and how it affects variables and their values. I had this issue with a DataTable and I want to know why a datatable is different than a simple integer variable. I have the physical answer on how to fix the problem but I want to know why it...

Default value to a parameter while passing by reference in C++

Is it possible to give a default value to a parameter of a function while we are passing the parameter by reference. in C++ For eg. when i try to declare a function like virtual const ULONG Write(ULONG &State = 0, bool sequence = true); when i do this it gives an error error C2440: 'default argument' : cannot convert from 'const i...

How to I pass a checkbox value by reference with CLI?

I have a GUI app written in C++/CLI which has a load of configurable options. I have some overloaded functions which grab values from my data source and I'd like to connect my options to those values. So here's a couple of data retrievers: bool GetConfigSingle(long paramToGet, String^% str, char* debug, long debugLength); bool GetConfi...

c++ * vs & in function declaration

Possible Duplicate: Difference between pointer variable and reference variable in C++ When should I declare my variables as pointers vs objects passed-by-reference? They compile to the same thing in assembly (at least run-time asymptotically) so when should I use which? void foo(obj* param) void foo(obj& param) ...

How can I pass a function by reference for a report callback in C++/CLI?

I have some code which handles data files and reports an error when it runs into trouble, but I'm having trouble working out how to give my class a callback function. Here's a quick example of the sort of thing I'm trying to achieve: public delegate void Reporter( System::String^ stringToReport ); /// <summary> /// Simple file handler ...

Visual Basic 6.0 Passing by reference problem

In the following code, I get a compile time error: ByRef Argument type mismatch. But if I change the declaration of i,j to : Dim i As Integer Dim j As Integer The error goes away. Why? Private Sub Command2_Click() Dim i, j As Integer i = 5 j = 7 Call Swap(i, j) End Sub Public Sub Swap(ByRef X As Integer, ByRef Y As In...

Visual Basic 6.0 Passing by Value Reference difference

In the following code, I get a compile time error because i is treated as a variant. The error is: "ByRef Argument type mismatch.". But if I pass the parameters ByVal, there is no error why? Private Sub Command2_Click() Dim i, j As Integer i = 5 j = 7 Call Swap(i, j) End Sub Public Sub Swap(ByRef X As Integer, ByRef Y...

PHP acts differently depending on computer

I have an issue with php where code works on on computer but wont work on another function appendParam(&$req, $name, $value) { if (req == null) { return; } if (name == null) { return; } if (value != null) { $req[$name] = $value; } } The above works on one computer and is capable of checking req and name against null pr...

Can I pass a simple value by reference in ColdFusion?

By default, ColdFusion passes simple types (like numeric, string, and GUID) by value to functions. I'd like to pass a simple type by reference. I'm currently wrapping a simple value in a struct (they get passed by reference). This solves my problem but it is very ugly: <!--- TheFunctionName----> <cffunction name="TheFunctionName"> ...

How to access original activity's views from spawned background service

I have an activity called A, and on the selection of menu item 0, it spawns service B, which starts a runnable C in a new thread. I have a TextView in activity A, which I want to access in thread C. I've tried making the TextView a public static field, but that generates the following error: 07-21 07:26:25.723: ERROR/AndroidRuntime(...

passing a string by reference to a function would speed things up? (php)

Possible Duplicate: In PHP (>= 5.0), is passing by reference faster? I wonder if by declaring the parameter pass by reference, the PHP interpreter will be faster for not having to copy the string to the function's local scope? The script turns XML files into CSVs, which have thousands of records, so little time optimizations cou...

How do I return a pointer to a user-defined class object using SWIG

I have the following code wrapped by swig: int cluster::myController(controller*& _controller) { _controller = my_controller; return 0; } controller has a private constructor. What's the correct incantation to make something like this not throw an exception? public static void main(String argv[]) { controller c = null; ...

How to pass a variable by value to an anonymous javascript function?

The Objective I want to dynamically assign event handlers to some divs on pages throughout a site. My Method Im using jQuery to bind anonymous functions as handlers for selected div events. The Problem The code iterates an array of div names and associated urls. The div name is used to set the binding target i.e. attach this event ...

PHP pass by reference in recursive function not working

I have two functions that I'm using to add or remove slashes from a deeply nested object/array combo. The first "level" of the array is always an object, but some of its properties may be arrays or objects. Here are my two functions: function objSlash( &$obj, $add=true ) { foreach ( $obj as $key=>$field ) { if ( is_object( $field )...

Better way for pass by reference from C# to C++?

Hello all, I have a 3rd party collection of .h files along with the .lib files that go with them. I am wrapping those native C++ files with a C++/CLI wrapper and making final calls from C#. I have an issue when I call methods that expect a reference to be passed in where the value is not getting changed in my wrapper unless I explicitl...