Skip to main content
Filter by
Sorted by
Tagged with
0 votes
5 answers
147 views

If statement vs. function pointer (performance)

Consider the following: while(running) { if(logMode == true) log(); bar(); } VS if (logMode == true) func_ptr = log; else func_ptr = noop; //noop is empty function that ...
Alex Mungan's user avatar
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 ...
Roee Zamir's user avatar
1 vote
1 answer
41 views

Problems with "qualified-id in declaration before '(' token" and "expected type-specifier" errors [duplicate]

I need to build some template classes in C++17 but I'm getting the following error message: When I do not define the macro __ALIAS__ I got an error on these lines: using PF = one<_Return>::...
Ulises V.'s user avatar
1 vote
3 answers
142 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 ...
Joel's user avatar
  • 1,755
2 votes
3 answers
179 views

Assign a non-static member function as a same class member variable, which is a function pointer

The example snippet: #include <iostream> #include <functional> #include <vector> // Simulated callback type using CallbackType = void(*)(void*, uint32_t); class DataProcessor{ ...
tesla1060's user avatar
  • 2,803
2 votes
1 answer
63 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? ...
Alphin Thomas's user avatar
2 votes
1 answer
76 views

How can I alias std::make_shared?

I have a template wrapper ThreadSafeVar for convenient mutex-locking of variables, and I want to alias std::shared_ptr and std::make_shared so I can do e.g. ThreadSafePtr<int> a = ...
H.v.M.'s user avatar
  • 1,718
2 votes
2 answers
47 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:...
Jennifer Nissitta's user avatar
3 votes
3 answers
120 views

Function pointers point to identical address values? ...sometimes

I have an array of function pointers and I want to assign simple dummy functions. The first thing that came to my mind was using lambda. That worked pretty well. The only thing that surprised me was ...
Jens's user avatar
  • 33
2 votes
1 answer
92 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 ...
marus's user avatar
  • 23
3 votes
1 answer
217 views

How to create an array of pointers to functions with arbitrary arguments?

I need an array of pointers to functions with unspecified amount of arguments. The return value is defined and it's void. I understand, that if the functions are going to be stored in an array of ...
dqvid's user avatar
  • 41
0 votes
1 answer
100 views

C struct pointers [duplicate]

#include <stdio.h> #include <stdlib.h> typedef struct node* Node; struct node{ int a; struct node* next; }; void insertAtBeginning(Node head){ Node temp = malloc(sizeof(struct node)); ...
Thirumal R's user avatar
2 votes
2 answers
111 views

What is the correct way to assign function to a function pointer of a structure member

Can anyone please help me with how to pass a function to a function pointer inside struct in C? I have a function as below typedef struct LOAD_DRV_DATA { uint8_t LoadDrvId; uint8_t dataLength; ...
Fatpanda's user avatar
1 vote
1 answer
61 views

GDB different function names and addresses than expected

I'm trying to capture when a child executes an abort. The following is a MCVE that should give an idea of what I'm trying to do. #include <iostream> #include <cstdio> #include <iomanip&...
SailorCire's user avatar
1 vote
3 answers
91 views

How to organise big array of structs with function references in it? [closed]

I am trying to make readable/maintanable file that contains big array of struct instances, which have function reference in it. Example of application, where this can be used, is user line command ...
user25555421's user avatar

15 30 50 per page
1
2 3 4 5
299