C isn’t that hard: void ( *( *f[] ) () ) ()

I just saw a picture today and think I’d appreciate explanations. So here is the picture: I found this confusing and wondered if such codes are ever practical. I googled the picture and found another picture in this reddit entry, and here is that picture: So this “reading spirally” is something valid? Is this how … Read more

Using generic std::function objects with member functions in one class

For one class I want to store some function pointers to member functions of the same class in one map storing std::function objects. But I fail right at the beginning with this code: #include <functional> class Foo { public: void doSomething() {} void bindFunction() { // ERROR std::function<void(void)> f = &Foo::doSomething; } }; I receive … Read more

Why do function pointer definitions work with any number of ampersands ‘&’ or asterisks ‘*’?

Why do the following work? void foo() { cout << “Foo to you too!\n”; }; int main() { void (*p1_foo)() = foo; void (*p2_foo)() = *foo; void (*p3_foo)() = &foo; void (*p4_foo)() = *&foo; void (*p5_foo)() = &*foo; void (*p6_foo)() = **foo; void (*p7_foo)() = **********************foo; (*p1_foo)(); (*p2_foo)(); (*p3_foo)(); (*p4_foo)(); (*p5_foo)(); (*p6_foo)(); (*p7_foo)(); } 5 … Read more

“unpacking” a tuple to call a matching function pointer

I’m trying to store in a std::tuple a varying number of values, which will later be used as arguments for a call to a function pointer which matches the stored types. I’ve created a simplified example showing the problem I’m struggling to solve: #include <iostream> #include <tuple> void f(int a, double b, void* c) { … Read more