function-pointers

Why does it seem that func is the same as &func in C? [duplicate]

杀马特。学长 韩版系。学妹 提交于 2020-12-26 03:50:55
问题 This question already has answers here : How does dereferencing of a function pointer happen? (5 answers) Closed last month . According to the GNU C manual, functions can be called using function pointers like so: func (j); /* (*func) (j); would be equivalent. */ So my reasoning here is: func itself is a pointer to the func(int) function. When you call func(j) , you are implicitly accessing the value of the pointer func (you are moving to the memory location where func is), in the same way as

Why does the address of a function change with every run?

烂漫一生 提交于 2020-12-25 04:29:19
问题 I'm struggling with mapping addresses to their symbols for debugging purposes (getting the callstack). The MS dbghelp.dll can tell the symbol from an address (see SymFromAddr , MSDN). However, it doesn't work and I wonder how this could ever work, because addresses seem to change with every run of the program: #include <iostream> void Foo() {} int _tmain(int argc, _TCHAR* argv[]) { const long unsigned int addr = reinterpret_cast<long unsigned int>(&Foo); std::cout << "Address: " << std::hex <

ISO C Void * and Function Pointers

我怕爱的太早我们不能终老 提交于 2020-08-21 06:06:57
问题 While following some tutorials and reading about function pointers I learned that evidently assigning a void pointer to a function pointer in ISO C is undefined, is there any way to resolve the warning I receive during compile time (e.g. a better way of coding it) or should I just ignore it? Warning: ISO C forbids assignment between function pointer and 'void *' [-pedantic] Example Code: void *(*funcPtr)(); funcPtr = GetPointer(); GetPointer is a function that returns a void pointer E.G. void

ISO C Void * and Function Pointers

喜夏-厌秋 提交于 2020-08-21 06:05:30
问题 While following some tutorials and reading about function pointers I learned that evidently assigning a void pointer to a function pointer in ISO C is undefined, is there any way to resolve the warning I receive during compile time (e.g. a better way of coding it) or should I just ignore it? Warning: ISO C forbids assignment between function pointer and 'void *' [-pedantic] Example Code: void *(*funcPtr)(); funcPtr = GetPointer(); GetPointer is a function that returns a void pointer E.G. void

Vector of fuctions_pointers whit different prototype, can i build one?

心不动则不痛 提交于 2020-08-08 05:38:25
问题 I'm doing a parsser for a class call virtual_machine, I'm trying to build a vectors of function for it, but some of those function on vm takes arguments (different numbers/types of arguments) can i still put those in my vector of fuction since they where only void (*f)(); here's the code class Virtual_Machine { public: /***/ void clear(); void pop(); void clear(); void assert(std::string const &value); void push(eOperandType const &e, std::string const &str); /***/ } class Parser { public: /*

Replace a function pointer in a shared library with ctypes

╄→尐↘猪︶ㄣ 提交于 2020-07-28 04:49:48
问题 I am trying to replace an existing function pointer in a shared library with a callback defined in Python, through ctypes. The source of the shared library in C: #include <assert.h> #include <stdio.h> void (*plot)(); int c_main(int argc, void** argv) { printf("plot is %p\n", (void*)plot); assert(plot != NULL); plot(); return 0; } The source of the Python script: from sys import platform from pathlib import Path import ctypes import _ctypes FUNCTYPE = ctypes.WINFUNCTYPE if platform == 'win32'