4,482 questions
1 vote
1 answer
57 views
Call function by reference in PowerShell [duplicate]
Suppose I have a function like this. How can I get a reference to that function and then call it? function Hello($name) { Write-Output "Hello, $name" }
1 vote
1 answer
127 views
Modernizing typedef for a function to std::function [duplicate]
I have legacy code which uses typedef for function pointers (and yes, void* as well). I reduced it to this: #include <memory> #include <functional> typedef void (*funx_t)(const double *, ...
4 votes
1 answer
167 views
How to use buffer overflow to modify function pointer value?
I am currently trying to make a code more safe for a cybersecurity exercise. I was asked to make the flag contained in the secret_function() come out. The problem is that I can't modify the code and ...
30 votes
6 answers
5k views
Why does K&R say that pointers are preferable to arrays as function parameters?
From K&R page 99: As formal parameters in a function definition, char s[]; and char *s; are equivalent; we prefer the latter because it says more explicitly that the variable is a pointer. I ...
1 vote
3 answers
180 views
How to avoid lambda capture in loop
Let's say I want to store a collection of function pointers (from lambdas), where each functions body is very similar. Writing everything out by hand gets repetitive and hard to manage, so instead I ...
2 votes
1 answer
91 views
Why does this function pointer typedef behave differently when used with const?
#include <stdio.h> typedef int (*func_t)(int); int foo(int x) { return x * 2; } int main() { const func_t ptr = foo; // Works //const func_t *ptr = &foo; // Fails: why? ...
2 votes
2 answers
64 views
Custom memory handling in postGIS
I am currently working on a c++ project leveraging the features of Postgis. Postgis provides handles to use custom memory allocators for the memory management. The allocator should be of the signature:...
2 votes
1 answer
110 views
How to Implement Universal Setter/Getter Functions for Interrupt-Driven Variables in Embedded C?
I had an interrupt functionality implementation in my embedded project with global variables. The interrupt checks PWM signal duty cycle and sets the value of a bool var to true if the value is ...