function

How can I assign values to a function pointers members in a structure

struct a { int (*ptr1)(); int (*ptr2)(); int data; }; typedef struct { struct a x; }all; int fun1() { return 5; }; int fun2() { return 9; }; I can assign like all *mem = (all*)malloc(sizeof(all)); mem->x.ptr1 = fun1; mem->x.ptr2 = fun2; Is there any other way to assign these function pointers? Is it possible to assi...

How to get a variable returned across multiple functions - Javascript/jQuery

This question in summary is to figure out how to pass variables between javascript functions without: returning variables, passing parameters between primary functions, using global variables, and forcing function 1 to wait for function 2 to finish. I figured out a jQuery solution and posted in below (in the answers section). Old Pos...

PHP: Make the loop and variable variables into a function

Hi, How can I make the code below into a function? # split the string by string on boundaries formed by the string delimiter will split the value into an array like the example below, # Array # ( # [0] => pg_cat_id=1 # [1] => tmp_id=4 # [2] => parent_id=2 # ) $array_parent = explode("&", $string); //print_r($array_parent); ...

Flex: ArrayCollection to XML conversion without SimpleXMLEncoder

Here are my functions for conversion: private function arrCol2XML(arrCol:ArrayCollection):XML { var xml:XML=new XML(<root></root>); for (var i:Number=0; i<arrCol.length; i++) { var obj:Object=arrCol.getItemAt(i); xml.appendChild(recursive(obj)); } return xml; } private function recursive(obj:Object, str:String='item'):XML { v...

Creating Nondeterministic functions in SQL Server using RAND()

After a bit of searching and reading the documentation, it's clear that you can write user defined functions in SQL Server that are marked as either deterministic or nondeterministic depending on which built-infunctions are used within the body. RAND() is listed under the nondeterministic functions (see msdn article). So why can't I use...

JavaScript: Access between two functions defined in global scope.

Hi there, can anyone explain the following to me. I have two JavaScript functions defined in global scope as follows: var foo = function () { var that = this; that.toString = function () { return "foobar" }; return that; }(); alert(foo.toString()); var foo2 = function (foo) { var that;...

php function foo(array $arg = NULL) -- why the array and NULL?

I've seen the following a few times lately: function foo(array $arg = NULL) { ... } My question being why make the default of $arg NULL when it will be just cast into an array? Why not do: function foo(array $arg = array()) { ... } I know it doesn't really make much difference--it's mostly just reading code--but why encourage PHP...

Setting the default value of a function input to equal another input in Python

Hello, Consider the following function, which does not work in Python, but I will use to explain what I need to do. def exampleFunction(a, b, c = a): ...function body... That is I want to assign to variable c the same value that variable a would take, unless an alternative value is specified. The above code does not work in pytho...

Create a concatenation function in SQL

Hi, Suppose I have a table a with one column b and three rows(1,2,3), I would like to create a function that will return '1,2,3' that would be called like this : SELECT FUNC(f), ... FROM ... In other words, I have a linked table that have more than one rows linked to each rows of the first table and would like to concatenate the conten...

Free Hosting Awardspace - Remote file calling via PHP

Hi, Awardspace being a big host free...services does seem to block all remote calls via PHP to scripts or even feeds to be called in my PHP Script What other alternatives I can use on Awardspace...does anyones have alternative to remote file funcitons ( curl , fsockopen , fopen , readfile , file_get_contents) to be used on Awardspace f...

Boost.Fusion Functional: Calling functions with default arguments

Is it possible to use boost::fusion::invoke function to call a function that has default arguments without specifying those? Example: void foo(int x, int y = 1, int z = 2) { std::cout << "The sum is: " << (x + y + z) << std::endl; } ... // This should call foo(0). It doesn't work because the type of foo is void (*) (int, int, int)....

ORA-00907 while trying to create a table with automatic column

I'm attempting to create a table with an automatic column, the value of which is computed using a function I've defined. However, when I try to create the table I keep getting ora-00907: Missing right parenthesis. Can anyone help? Here is the CREATE code: CREATE TABLE NEW_EMP2 ( SSN CHAR(9), EMP_NUM2 CHAR(5) automatic as newemp2id(SSN...

C++: Can't work with simple pointers?

I apologize as this is so simple, I was working with my own XOR swap method and wanted for the heck of it compare the speed difference between reference and pointer use (do not spoil it for me!) My XOR ptr function is as follows: void xorSwapPtr (int *x, int *y) { if (x != y && x && y) { *x ^= *y; *y ^= *x; ...

How to return a value from a function in AS3? Then store than value in a variable to pass it to another function?

I am trying to have the function toggleClick return powerData. I need to store powerData in a variable and have it passed to another function to do calculations. Inside the function toggleClick, I am assigning powerData to houseArray[e.currentTarget.name.toLowerCase()]; var powerData:int = houseArray[e.currentTarget.name.toLowerCas...

javascript - shortcut for calling a function at the same time it is defined

hi, to call a function at the same time it's defined, i had been using: var newfunc = function() { alert('hi'); }; newfunc(); is the following the correct way of combining these 2: var newfunc = function() { alert('hi'); }(); ...

Is there a PHP function for swapping the values of two variables?

Say for instance I have ... $var1 = ABC $var2 = 123 and under certain conditions I want to swap the two around like so... $var1 = 123 $var2 = ABC Is there a PHP function for doing this rather than having to create a 3rd variable to hold one of the values then redefining each, like so... $var3 = $var1 $var1 = $var2 $var2 = $var3 ...

Default argument values in subroutines

I have been working with perl for about two months now; it just occurred to me that I don't know how to set default arguments for subroutines. Here is what I considered: sub hello { print @_ || "Hello world"; } And that works fine for if all you needed was one argument. How would you set default values for multiple arguments? I was ...

MySQL Function to Determine Zip Code Proximity / Range

I have been able to create php function to determine a list of zip codes within a certain range of a given zip code. However, my next task is a bit more complex. Lets say the table has the following columns: id, username info latitude longitude range Each record has a unique row id, some information, a latitude, a longitude, and a ma...

php query function / class

It must be Monday, the heat or me being stupid (prob the latter), but for the life of me I cannot get a simple php function to work. I have a simple query $sql = mysql_query("SELECT * FROM table WHERE field_name = '$input'"); Which I want to run through a function: say: function functionname($input){ global $field1; global...

Create function to loop through properties of a method in C#?

What I am trying to do is create a function that will be called from each method within a .cs file to then get all of the property names and values that are passed to the method and create a string of them. This will be used for a debug log to show what the value of each property was when the error occurred as an alternative to manually...