Tagged Questions
1
vote
2answers
339 views
How do I default initialize function pointer in c/c++?
I am passing a function pointer to another function, and I want it to be default initialized,
and this is what I am trying, but this gives syntax error
void bar(int i) {}
void foo(void ...
0
votes
2answers
74 views
Result of unary & operator applied to a function
C99 6.3.2.1/4
A function designator is an expression that has function type. Except
when it is the operand of the sizeof operator or the unary &
operator, a function designator with type ...
13
votes
2answers
298 views
Helping the compiler optimize function pointers
A common way of implementing OO-like code encapsulation and polymorphism in C is to return opaque pointers to a structure containing some function pointers. This is a very frequent pattern for example ...
0
votes
1answer
115 views
GCC C thinks I'm declaring a function as static? [closed]
So I have a header file and 2 .c files within the beginnings of my program. I go to compile and I get the error message (tons of these over and over)
command_parser.c:74:6: error: static declaration ...
11
votes
3answers
285 views
Functional Programming (Currying) in C / Issue with Types
As a dyed-in-the-wool functional programmer I find it hard not to try to shoehorn my favourite paradigm into whatever language I'm using. While writing some C I found I'd like to curry one of my ...
3
votes
1answer
174 views
Function pointer conversion in C
As I heard, It is not safe to convert pointer to function to void*.
Okay, is it safe to cast
void (*enumerate) (void (*)(const struct foo *event, void *), void *)
to
void (*enumerate) (void ...
0
votes
1answer
1k views
C function pointers error storage class specified for parameter `type name'
I currently have a piece of code that I am working on using function pointers as callbacks. I am having trouble with an error from gcc stating "storage class specified for parameter `type name'" The ...
3
votes
2answers
518 views
Function pointer to __attribute__((const)) function?
How (in GCC/"GNU C") do you declare a function pointer which points to an __attribute__((const)) function? The idea being that I want the compiler to avoid generating multiple calls to the function ...
1
vote
1answer
172 views
What are the penalties of generic functions versus function pointer arrays in C?
I'm writing a matrix library (part of SciRuby) with multiple storage types ('stypes') and multiple data types ('dtypes'). For example, a matrix's stype may currently be dense, yale (AKA 'csr'), or ...
5
votes
2answers
297 views
Function pointer with GCC, assigning an address
I have encountered something I thoroughly don't understand.
There is a function prototype:
typedef void ( * TMain ) ( void );
and a function variable:
TMain myFunc = MyFunc;
...
myFunc ();
This ...
9
votes
3answers
3k views
C: How do I get the name of the calling function?
I am using gnu tool chain. How can I, at run time, find caller of a function? i.e for example function B() gets called by many functions using function pointers. Now, whenever B gets called, I want to ...
5
votes
7answers
278 views
why is the address of a c++ function always True?
well why would,
#include <iostream>
using namespace std;
int afunction () {return 0;};
int anotherfunction () {return 0;};
int main ()
{
cout << &afunction << endl;
}
...
0
votes
1answer
551 views
How to find the address & length of a C++ function at runtime (MinGW)
As this is my first post to stackoverflow I want to thank you all for your valuable posts that helped me a lot in the past.
I use MinGW (gcc 4.4.0) on Windows-7(64) - more specifically I use Nokia Qt ...
6
votes
1answer
2k views
error: invalid conversion from 'void (*)()' to 'void (*)()' — what?
I am trying to pass a callback function from C++ to OpenGL (C API):
gluQuadricCallback(qobj, GLU_ERROR, errorCallback);
where errorCallback is a function in a file compiled as C++ code and is ...
1
vote
3answers
377 views
reference to void
I have a sneaky feeling this may be an issue due to compilers.
void SetRenderFunction(void (&newRenderFunction(void)));
This is causing GCC to proclaim that I "cannot declare reference to ...