variables

PHP Variables passed by value or by reference?

I had a Java developer new to PHP ask me this question the other day, so I thought I'd document the answer here. Question: are PHP variables passed by value or by reference?...

Accessing OpenGL state variables in Cg

I need to access the OpenGL state variables (such as the MVP matrices) in my Cg shader program. I'm passing these values to my Cg shader program manually using calls such as cgGLSetStateMatrixParameter() in my C/C++ code. Is there an easier way to do this? ...

Comparing IEEE floats and doubles for equality

What is the best method for comparing IEEE floats and doubles for equality? I have heard of several methods, but I wanted to see what the community thought. ...

How do you use script variables in PostgreSQL?

In MS SQL Server, create my scripts to use customizable variables: declare @somevariable int select @somevariable = -1 insert into foo values ( @somevariable ) I'll then change the value of @somevariable at runtime, depending on the value that I want the particular situation. Since it's at the top of the script it's easy to see & reme...

What's the best way to return multiple values from a function in Python?

I have a function where I need to do something to a string. I need the function to return a boolean indicating whether or not the operation succeeded, and I also need to return the modified string. In C#, I would use an out parameter for the string, but there is no equivalent in Python. I'm still very new to Python and the only thin...

When do function-level static variables get allocated/initialized?

I'm quite confident that globally declared variables get allocated (and initialized, if applicable) at program start time. int globalgarbage; unsigned int anumber = 42; But what about static ones defined within a function? void doSomething() { static bool globalish = true; // ... } When is the space for globalish allocated? I'm...

Ruby - Get a Variable's Name

I'm not entirely sure if this is possible in Ruby, but hopefully there's an easy way to do this. I want to declare a variable and later find out the name of the variable. That is, for this simple snippet: foo = ["goo", "baz"] How can I get the name of the array (here, "foo") back? If it is indeed possible, does this work on any variab...

In PHP is it possible to use a function inside a variable

I know in php you can embed variables inside variables, like: <? $var1 = "I\'m including {$var2} in this variable.."; ?> But I was wondering how, and if it was possible to include a function inside a variable. I know I could just write: <?php $var1 = "I\'m including "; $var1 .= somefunc(); $var1 = " in this variable.."; ?...

How to determine the value of a controller variable during execution in Ruby on Rails?

What is the best way for me to determine a controller variable's value during execution? For example, is there a way I can insert a break in the code, and cause the value of the variable to be output to the screen (or the log)? ...

is there a way to write macros with a variable argument list in visual C++?

As far as I know, in gcc you can write something like: #define DBGPRINT(fmt...) printf(fmt); Is there a way to do that in VC++? ...

How do I pass a variable to a mysql script?

I know that with mysql you can write SQL statements into a .sql file and run the file from the mysql command line like this: mysql> source script.sql How do I pass a variable to the script? For example, if I want to run a script that retrieves all the employees in a department, I want to be able to pass in the number of the department...

Print variable type in C++

Is it possible in standard C++ to print a variable type. I think this is being addressed in C++0x but not sure it already exists. I would like something like this: int a = 12; cout << typeof(a) << endl; That would print: int ...

How might I pass variables through to cached content in PHP?

Essentially I have a PHP page that calls out some other HTML to be rendered through an object's method. It looks like this: MY PHP PAGE: // some content... <?php $GLOBALS["topOfThePage"] = true; $this->renderSomeHTML(); ?> // some content... <?php $GLOBALS["topOfThePage"] = false; $this->renderSomeHTML(); ?> The fi...

Perl: variable scope issue with CGI & DBI modules

I've run into what appears to be a variable scope issue I haven't encountered before. I'm using Perl's CGI module and a call to DBI's do() method. Here's the code structure, simplified a bit: use DBI; use CGI qw(:cgi-lib); &ReadParse; my $dbh = DBI->connect(...............); my $test = $in{test}; $dbh->do(qq{INSERT INTO events VALUES (?...

session variable mixup in ASP.NET?

Is it possible for ASP.NET to mix up which user is associated with which session variable on the server? Are session variables immutably tied to the original user that created them across time, space & dimension? ...

What kind of prefix do you use for member variables?

No doubt, it's essential for understanding code to give member variables a prefix so that they can easily be distinguished from "normal" variables. But what kind of prefix do you use? I have been working on projects where we used m_ as prefix, on other projects we used an underscore only (which I personally don't like, because an under...

Python-passing variable between classes

I'm trying to create a character generation wizard for a game. In one class I calculate the attributes of the character. In a different class, I'm displaying to the user which specialties are available based on the attributes of the character. However, I can't remember how to pass variables between different classes. Here is an example ...

Pointer vs. Reference

What would be better practice when giving a function the original variable to work with: unsigned long x = 4; void func1(unsigned long& val) { val = 5; } func(x); or: void func2(unsigned long* val) { *val = 5; } func2(&x); IOW: Is there any reason to pick one over another? ...

reinitialize system wide environment variable in linux

I just want my apache to register some of my predefined environment so that i can retrieve it using getenv function in php. How can i do this? I tried adding /etc/profile.d/foo.sh with export FOO=/bar/baz using root and restarted apache. ...

Finding the name of a variable in C

I was asked a question in C last night and I did not know the answer since I have not used C much since college so I thought maybe I could find the answer here instead of just forgetting about it. If a person has a define such as: "#define count 1" Can that person find the variable name "count" using the 1 that is inside it? I did no...