function

Why pass by const reference instead of by value?

From what I understand: when you pass by value, the function makes a local copy of the passed argument and uses that; when the function ends, it goes out of scope. When you pass by const reference, the function uses a reference to the passed argument that can't be modified. I don't understand, however, why one would choose one over the o...

Flash Builder 4: Call main function from a component function

i try to make a login sistem in flex, and my app looks like this: i have a main.mxml. when the app loads, a function named "start" is called. it verifies if the user is logged in or not. if "true" the user is redirected to a dashboard, if "false", a component named login is loaded. my login.mxml component has 2 input boxes (user & pass...

Language construct naming: Function/Goto

How is a language construct with the following properties called? It has a beginning and an end, just like a function It has a header containing it's name, also like a function but without arguments There can be any number of statements between its beginning and end, like a function You can use a function to jump to its beginning from ...

Does the return value of a MATLAB function depend on how it's called?

A = imread(filename, fmt) [X, map] = imread(...) The above is in the synopsis part of imread, which seems to say that the return value of a MATLAB function depends on how it's called? Is that true? ...

C++ pointer to functions, Beginner Question...

Hi all, I want to ask about pointer in C++ I have some simple code: int add(int a, int b){ return a+b; } int runner(int x,int y, int (*functocall)(int, int)){ return (*functocall)(x,y); } now, suppose I call those functions using this way : cout<<runner(2,5,&add); or maybe cout<<runner(2,5,add); is there any difference? beca...

Problem using void pointer as a function argument

Hi, I can't understand this result... The code: void foo(void * key, size_t key_sz) { HashItem *item = malloc(sizeof(HashItem)); printf("[%d]\n", (int)key); ... item->key = malloc(key_sz); memcpy(item->key, key, key_sz); } void bar(int num) { foo(&num, sizeof(int)); } And I do this call: bar(900011009); ...

What is the point of function pointers?

Hi, I have trouble seing the utility of the function pointers. I guess it may be useful in some cases (they exist, after all), but I can't think of a case where it's better or unavoidable to use a function pointer. Could you give some example of good use of function pointers (in C or C++)? Many thanks :) ...

jQuery function in .click() etc

Hi all. So normally, I do it like this: $('#selectRoom a').click( function(e) { e.preventDefault(); // To prevent the default behavior (following the link or adding # to URL) // Do some function specific logic here }); However, I would like to do it like this, to clean things up (and be able to reuse): $('#selectRoom a').click( sel...

Assistance with Lua functions

As noted before, I'm relatively new to lua, but again, I learn quick. The last time I got help here, it helped me immensely, and I was able to write a better script. Now I've come to another question that I think will make my life a bit easier. I have no clue what I'm doing with functions, but I'm hoping there is a way to do what I wa...

Is it possible to view the "source" for a ksh function?

Our ksh environment defines several functions. The names of these functions can be listed using then typeset -f ksh command (or the functions alias). Is it possible to see the definition (ie source code) for these functions? This seems like an obvious question, but I've tried all manner of parameters to typeset -f with no luck. As an...

Help with PHP function that will take $bytes and $rate (per GB) and return $total

I was hoping someone might help with a function that given two parameters: @param $bytes : total amount in bytes of data consumed @param $rate : rate per GB, example .22 (for 22 cents) @returns Total amount owed Rounded to nearest cent of course. Thanks in advance for any help. ...

Help on understanding JS

I have thos piece of code: Math&&Math.random?Math.floor(Math.random()*10000000000000):Date.getTime(); And as far as i know && is logic operator for AND, so im trying to convert this into PHP and this is where i got: intval(floor(time()/10800000)%10+(rand()?floor(rand()*10000000000000):time())) The problem is that i can't understand...

Ruby - print the variable name and then its value

What is the best way to write a function (or something DSLish) that will allow me to write this code in Ruby. How would I construct the function write_pair? username = "tyndall" write_pair username # where write_pair username outputs username: tyndall Is it possible to do? Looking for the most simple way to do this. ...

C question on functions

some times i see that functions are defined as below: read_dir(dir) char *dir; { DIR * dirp; struct dirent *d; /* open directory */ dirp = opendir(dir); ......... so on here what is the importance of the statement char *dir; what is the intension behind declaring the pointer soon afte...

Code equivalence between Javascript and PHP

I'm trying to learn PHP and I wish to know if there are some function equivalence constructs: In JS I can do: var t = function() {}; t(); myObj.DoStuff = function() {} // here I add a method at run-time myObj.DoStuff(); myObj["DoStuff"](); var j = myObj.DoStuff; j(); and so other things with function evaluation. In Js objects are...

Nested function in C

Can we have a nested function in C? What is the use of nested functions? If they exist in C does there implementation differes from compiler to compiler. Are nested functions allowed in any other language? If yes then what is there significance? ...

Language Design: Combining Gotos and Functions

I'm designing and currently rethinking a low-level interpreted programming language with similarities to assembler. I very soon came across the functions/loops/gotos decision problem and thought that while loops like while and for would be too high-level and unfitting, gotos would be too low level, unmaintainable and generally evil agai...

Python nested function scopes

I have code like this: def write_postcodes(self): """Write postcodes database. Write data to file pointer. Data is ordered. Initially index pages are written, grouping postcodes by the first three characters, allowing for faster searching.""" status("POSTCODE", "Preparing to sort...", 0, 1) # This function returns t...

Arrays become null after passing to function in PHP

So when I pass my filled arrays to the function createform the form is created with $max_avatars options, but they have no name or value. Why are my arrays becoming null? <?php $avatar_image_name = array('hacker','samurai','cool','happy','thatsnice','angry','tv','bang'); $avatar_name = array('Hacker','Samurai','Cool','Happy'...

jQuery Validate() special function

I'm using the jQuery validate() plugin for some forms and it goes great. The only thing is that I have an input field that requires a special validation process. Here is how it goes: The jQuery validate plugin is called in the domready for all the required fields. Here is an example for an input: <li> <label for="nome">Nome comple...