function

How does casting a function actually work in C?

int foo(char *c) {...} main() { int (*thud)(void *); thud = (int (*)(void *))(foo); } What actually happens during the evaluation of the assignment? There is a difference between the cast type and foo; the cast type is a pointer and foo is a function. So, does the compiler convert what's in '(foo)' into a pointer to foo ...

Using functions in PHP?

How do I simply call a function by using PHP? Say I have created: function sam(){ echo "Hello World!; exit(); } How would I initiate the function? ...

What is the difference between function and procedure in PL/SQL?

Duplicate: what is the difference between a function and a procedure What is the difference between function and procedure in PL/SQL ? ...

Finding how a foreach collection gets modified

Hello everyone, How do I find out which function or target is modifying the items in a foreach loop in a multithreaded application? I continously keep getting the error "Collection was modified; enumeration operation may not execute". I'm not removing or adding any items to the generic list within the for loop. I want to find out how it...

newid() inside sql server function

i have to insert a fake column at the result of a query which is the return value of a table-value function. this column must be uniqueidentifier type. the best way (i think ...) is to use 'newid()' function. the problem is I can't use the 'newid()' inside this type of function: Invalid use of side-effecting or time-dependent operator i...

[Beginner] JQuery reusable functions

Completely new to JQuery so I am learning everyday. One thing I noticed is how easy it is, you can just write $('div#test).remove(); But I am looking for an example on how to reuse some code, eg.: function RemoveTableRow(row, id) { $(row).remove(); // id should be used for ajax call } And then add a 'onclick' on my anchor-...

We know log_add, but how to do log_subtract?

Multiplying two numbers in log space means adding them: log_multiply(x, y) = log( exp(x) * exp(y) ) = x + y Adding two numbers in log space means you do a special log-add operation: log_add(x, y) = log( exp(x) + exp(y) ) which is implemented in the following code, in a way that doesn't require us to take the two ...

Functional Style Web Frameworks

All the web frameworks that I have seen mostly follow the OO paradigm. Are there any web frameworks in Python or Ruby which follow the FP style? ...

C/C++: Static function in header file, what does it mean?

I know what it means when declared in source file. I reading some code, find that static function in header files could be invoke in other files. ...

Implementing a 'function-calling function'

I would like to write a bit of code that calls a function specified by a given argument. EG: def caller(func): return func() However what I would also like to do is specify optional arguments to the 'caller' function so that 'caller' calls 'func' with the arguments specified (if any). def caller(func, args): # calls func with th...

Call a function from an object : object.function()

How can I call a function from an object in javascript, like for example in jquery you call myDiv.html() to get the html of that div. So what I want is this to work : function bar(){ return this.html(); } alert($('#foo').bar()); this is a simplified example, so please don't say : just do $('#foo').html() :) ...

Jquery Function for skipping to a textbox on keypress

Hi all, I currently have 4 textboxes which will be used to store an ip address. What i need help with is a function that will allow a user to input a "." and have the textbox change focus from the current textbox to the next textbox. Thanks in advance ...

One line functions in C?

What do you think about one line functions? Is it bad? One advantage I can think of is that it makes the code more comprehensive (if you choose a good name for it). For example: void addint(Set *S, int n) { (*S)[n/CHAR_SIZE] |= (unsigned char) pow(2, (CHAR_SIZE - 1) - (n % CHAR_SIZE)); } One disadvantage I can think of is that it...

Function for week of the month in mysql

I was looking for a simple function to get the week of the month (rather than the easy week of the year) in a mysql query. The best I could come up with was: WEEK(dateField) - WEEK(DATE_SUB(dateField, INTERVAL DAYOFMONTH(dateField)-1 DAY)) + 1 I'd love to know if I'm reinventing the wheel here, and if there is an easier and cleaner s...

C#: Using new in a Func<T>

I was wondering, after having read this question... he has this code: public static T FindOrCreate<T>(this Table<T> table, Func<T, bool> find) where T : new() { T val = table.FirstOrDefault(find); if (val == null) { val = new T(); table.InsertOnSubmit(val); } return val; } Would it be possible ...

How can I write an function in objective-c, that I can use over any object in my iPhone app?

I want to create an function which I pass an object. Then, this function should print out some information for me. like: analyzeThis(anyObject); I know about methods, but not how to make a function. As I understand, a function works global in all methods and classes, right? ...

Declaring external functions depending on whether they exist

Hi. I would like to declare an external function from the kernel32.dll library whose name is GetTickCount64. As far as I know, it is defined only in Vista and in later Windows versions. This means that when I define the function as follows: function GetTickCount64: int64; external kernel32 name 'GetTickCount64'; I will certainly not ...

PHP including in functions

I'm working on changing over a large, somewhat poorly written (but not terribly so), PHP website to use a class which stores functions which do things like write the standard page header with arguments to change things like the text of the header. The old version used a copied and pasted HTML header in each file with something like: <di...

A need to get data from a table and then use that data for a query

I would like to write a PHP function that calls another function Page 1. User selects item from drop down. (I then post to the same page.) Page 1. (I have a query on the page that's based off of which item is selected) (In this case I'm returning the lat and long of the item.) $latitude = $row_farms['lat']; $longitude = $row_farms['...

How can I create a piecewise inline function in MATLAB?

I have a function in MATLAB which takes another function as an argument. I would like to somehow define a piecewise inline function that can be passed in. Is this somehow possible in MATLAB? Edit: The function I would like to represent is: f(x) = { 1.0, 0.0 <= x <= 0.5, -1.0, 0.5 < x <= 1.0 where 0.0 <= x <= 1.0 ...