function

In pure C how can I pass a variable number of parameters into a function?

Hey, How can i pass (and access) using C, not c++, variable parameters into a function? void foo(char* mandatory_param, char* optional_param, char* optional_param2...) thanks /fmsf ...

Get page permalink and title outside the loop in wordpress

Hello, How to Get page permalink and title outside the loop in wordpress. I have a function like function get_post_info(){ $post; $permalink = get_permalink($post->ID); $title = get_the_title($post->ID); return $post_info('url' => $permalink, 'title' => $title); } when this function called within the loop, it returns the pos...

SQL function to get count of how many times string appears in column?

Is there a function for MySQL that will count the number of times a string occurs in another string or column? Basically I want: SELECT SUB_COUNT('my word', `my_column`) AS `match_count` FROM `table` Thanks! EDIT: I need to know how many times the string appears in a column for each row in a SELECT. ...

Converting code to perl sub, but not sure I'm doing it right

I'm working from a question I posted earlier (here), and trying to convert the answer to a sub so I can use it multiple times. Not sure that it's done right though. Can anyone provide a better or cleaner sub? I have a good deal of experience programming, but my primary language is PHP. It's frustrating to know how to execute in one lan...

Static Variables in Overloaded Functions

I have a function which does the following: When the function is called and passed a true bool value, it sets a static bool value to true When the function is called and passed a string, if the static bool value is set to true, it will do something with that string Here is my concern -- will a static variable remain the same between ...

Need for prefixing a function with (void)...

Hi All, I recently came across a rather unusual coding convention wherein the call for a function returning "void" is prefixed with (void). e.g. (void) MyFunction(); Is it any different from the function call like: MyFunction(); Has it got any advantage or is it yet another needless but there coding convention of some...

jQuery .toggle() not working as expected with second function?!

I'm trying to create a button to show / hide a div below it, all is working fine, I'm just struggling with the last bit! I need to distinguish wether it's a show or hide action so I can pass the variable elsewhere, here's what I have.. $(this).find('.hide-close').click( function() { $(this).siblings('.dragbo...

What are good uses for Python3's "Function Annotations"

Function Annotations: PEP-3107 I ran across a snippet of code demonstrating Python3's function annotations. The concept is simple but I can't think of why these were implemented in Python3 or any good uses for them. Perhaps SO can enlighten me? How it works: def foo(a: 'x', b: 5 + 6, c: list) -> max(2, 9): ... function body ... ...

PHP - Use isset inside function not working..?

I have a PHP script that when loaded, check first if it was loaded via a POST, if not if GET['id'] is a number. Now I know I could do this like this: if(isset($_GET['id']) AND isNum($_GET['id'])) { ... } function isNum($data) { $data = sanitize($data); if ( ctype_digit($data) ) { return true; } else { ret...

Interface function C#

Hello, I have a function which implement an interface. something like this: string IMyInterface.MyFunction() { do something; } This function is available outside of my class. All working perfect. Now I also need to call this function from another LOCAL non public function. like this: void Func2() { string s; s = MyFunction(); ...

prevent using functions before initialization, constructors-like in C

This is the way I get to prevent funA,funB,funC, etc.. for being used before init #define INIT_KEY 0xC0DE //any number except 0, is ok static int initialized=0; int Init() { //many init task initialized=INIT_KEY; } int funA() { if (initialized!=INIT_KEY) return 1; //.. } int funB() { if (initialized!=INIT_KEY) return 1; //....

Passing template into boost function

template <class EventType> class IEvent; class IEventable; typedef boost::function<void (IEventable&, IEvent&)> behaviorRef; What is the right way for passing template class IEvent into boost function? With this code I get: error: functional cast expression list treated as compound expression error: template argument 1 is invalid err...

PHP: variable not working inside of function?

hi guys, echo $path; //working function createList($retval) { echo $path; //not working print "<form method='POST' action='' enctype='multipart/form-data'>"; foreach ($retval as $value) { print "<input type='checkbox' name='deletefiles[]' id='$value' value='$value'>$value<br>"; } print "<input class='subm...

Template problems: No matching function for call

I'm trying to create a template class, and when I define a non-member template function, I get the "No matching function for call to randvec()" error. I have a template class defined as: template <class T> class Vector { T x, y, z; public: //constructors Vector(); Vector(const T& x, const T& y, const T& z); Vector(const Vector& u); /...

What is DEFAULT_CC in function declaration?

I'm relatively new to C, and am curious what this syntax means in a function declaration: int DEFAULT_CC foo(void) where DEFAULT_CC is probably defined somewhere else as: #define DEFAULT_CC "something" (I realized the previous example I had up had to do with something completely irrelevant). ...

How to define and use a friend function to a temlate class with the same template?

I have written the following code: #include <iostream> using namespace std; template <class T> class AA { T a; public: AA() { a = 7; } friend void print(const AA<T> & z); }; template <class T> void print(const AA<T> & z) { cout<<"Print: "<<z.a<<endl; } void main() { AA<int> a; print<int>(a); } And getting the following ...

A function where small changes in input always result in large changes in output

I would like an algorithm for a function that takes n integers and returns one integer. For small changes in the input, the resulting integer should vary greatly. Even though I've taken a number of courses in math, I have not used that knowledge very much and now I need some help... An important property of this function should be that ...

Passing an array of data to a private function in CodeIgniter/PHP? [facepalm]

So I thought this should be easy, but, I'm n00bing out here and failing epicly (as they say on teh interwebz). So here's my code: function xy() { $array['var1'] = x; $array['var2'] = y; echo $this->_z; } function _z($array) { $xy = $x.$y; return $xy; } So, why doesn't that seemingly simple code work? I know with views you ...

Smarty template tag to check for FIRST user login - to pass message on initial login

Hello, I usually don't use Smarty but am in the process of editing a prebuilt app, that uses Smarty for templating. It's super easy to check for the login status, but I have searched the Smarty site, docs and the app vendors docs and cannot find a tag of function to check for the initial user login. We need to pass a message to the user ...

Mathematica: get number of arguments passed to a function?

How do I get the number of arguments passed to a function, such as Plus[2,3,4,5] has 4 arguments passed to it. I was thinking it may involve the use of the function Length and getting the arguments into a list. The intention is to iterate an operation based on the number of arguments for a function. There is probably a simple solution or...