1,401 questions
4
votes
2
answers
140
views
Accessing constant variables from a lambda in Visual Studio 2026
I have a program that I would like to build in Visual Studio 2026, but struggle with the errors appearing.
One simplified piece of code is as follows:
void f(const void*) {}
int main() {
...
Advice
1
vote
9
replies
83
views
What are examples of problems arising from casting between void pointer and function pointers?
I read online that casting void* to any function pointer produces undefined behaviour in C. I printed the sizeof(void*) and sizeof(&some_func) and both are 8 bytes.
Given that both types have the ...
Advice
0
votes
14
replies
6k
views
Casting functions with pointer arguments to function pointers with void* argument
The following code is accepted by GCC and the resulting binary prints the expected results. But is it standard conform and would always work on different systems using different compilers?
Minimal ...
1
vote
2
answers
184
views
Getting type of a pointer
I've created the function
void add_entry(char key[], void* value, char file[], ValueType type)
and I want to use my generic function to get the typeof the pointer
#define typeof(x) _Generic((x), \
...
3
votes
1
answer
89
views
Accessing any object type from multiprocessing shared_memory?
Suppose I create a shared memory object:
from multiprocessing import shared_memory
shm_a = shared_memory.SharedMemory(create=True, size=1024)
buffer = shm_a.buf
and put a generic object of a generic ...
1
vote
1
answer
79
views
Level of type casting of pointers?
I have an array of pointers to structs in C as
typedef struct{
int elem1;
char *elem2;
...
}example_t;
example_t *array[MAX_SIZE];
I did generic functions for add or delete pointers to ...
4
votes
1
answer
203
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 ...
3
votes
2
answers
130
views
How to avoid getting warning assignment of different pointer when passing function with specific type parameters?
I have written this example to try and explain the problem.
I have defined a function as follows:
// Return name from given user.
typedef char *(name)(void *user);
And then implemented this function ...
1
vote
1
answer
139
views
Generic Quad Tree implementation in C
Context
I've been trying to learn C and have become a little more comfortable in it recently. I am building a 2d space shooting game (kind of Galaga inspired, written using SDL) and decided to use ...
0
votes
1
answer
55
views
Using a function to allocate complex custom data structures
I am trying to allocate memory for certain data structures (array, matrix, custom_array, ...). The problem I think I am facing is that I am not able to cast the proper types to the passed pointers ...
0
votes
2
answers
129
views
Why do I get a SEGFAULT when I try to sort an array of integers using K & R code examples? [closed]
I'm trying to work my way through The C Programming Language, 2nd Edition, and I can't get my head around exactly what is happening in the following code.
The example from the book works just fine ...
1
vote
1
answer
525
views
How to fix "multi level implicit pointer conversion" warning in clang-tidy?
I have some legacy code that reads like this:
bool has_attribute(int kvidx) const {
void* v = nullptr;
int flag = 0;
MPI_Comm_get_attr(impl_, kvidx, &v, &flag);
return flag != ...
0
votes
5
answers
245
views
Disadvantages of using void * to hold generic objects?
I'm a C beginner, and I've got a question while I read the Chapter 19.5 of C Programming: A Modern Approach (2nd Edition) by K. N. King.
In this chapter, the author explains what is program design and ...
2
votes
3
answers
181
views
Why pass void pointer instead of custom type?
Setup
I'm taking over code from another person. I found a coding pattern that seems odd to me. This is for an embedded 32 bit PIC processor, in case that's relevant.
They have a custom typedef in a ...
0
votes
0
answers
34
views
Void Typecasting - Middle of Structure
I'm attempting to write a program that takes data from main (member type structure), then passes it to (void *) within the function, placing it on the stack in a linked list. In order to use this ...