void-pointers

De-referencing void pointer to a pointer array

混江龙づ霸主 提交于 2021-02-16 15:39:26
问题 I'm using a threading library given to me at school and having trouble understanding how to pass a reference of an array of pointers to a method, or rather, I'm having trouble de-referencing and using the pointer array. The situation that I (believe I) understand is this: int main(void) { Foo* bar = new Foo(); // Passing instance of Foo pointer by reference CThread *myThread = new CThread(MyFunction, ACTIVE, &bar); return 0; } UINT __stdcall MyFunction(void *arg) { Foo* bar = *(Foo*)(arg);

De-referencing void pointer to a pointer array

≯℡__Kan透↙ 提交于 2021-02-16 15:39:25
问题 I'm using a threading library given to me at school and having trouble understanding how to pass a reference of an array of pointers to a method, or rather, I'm having trouble de-referencing and using the pointer array. The situation that I (believe I) understand is this: int main(void) { Foo* bar = new Foo(); // Passing instance of Foo pointer by reference CThread *myThread = new CThread(MyFunction, ACTIVE, &bar); return 0; } UINT __stdcall MyFunction(void *arg) { Foo* bar = *(Foo*)(arg);

C change the value a void pointer represents

一曲冷凌霜 提交于 2021-02-11 12:41:48
问题 This is a follow up to this question: Having a function change the value a pointer represents in C As an exercise, I am trying to make a generic function that changes a value in an array of undetermined type. I guess it should look like that. void set_value(void * data, void * value, size_t size, int index){ void * position = data + index*size; *position = *value; } Of course that does not compile, *position = *value do not use the information of the size of value (here was assume both data

Can a type of variable be an object in C++?

天涯浪子 提交于 2021-01-29 06:09:02
问题 I hope my question is clear. I would like to do something like this: TYPE tipo = int; tipo = float; To later be able to do other things like these: void* ptr = new tipo(); cout << *(tipo*)ptr; It's, basically, to determinate the type of a void-pointer (or a variant -object, or a any -object) and its de-reference, but in execution time. This is my whole problem: I'm trying to create an array of any type of variable (simulating the RAM of a PC for a compiler). For this I'm using void pointers

C++: Is it posible to set the type of a void-pointer, variant-object or any-object in execution time?

孤者浪人 提交于 2021-01-28 23:22:14
问题 Void-pointer, variant-objects and any-objects are amazing because they can store many different types in the same variable. But I have a problem with them, I need to specify their type (creating and/or de-referencing them) in the execution time, is it possible? To be more clear, for example, as far I know, to create and de-reference them I have to do this: void* ptr = new int(8); variant<int, float> var = 8; any a = 8; ... cout << *(int*)ptr; cout << get<int>(var); cout << any_cast<int>(a);

Using void pointer to simulate a generic linkedlist in C

ぃ、小莉子 提交于 2021-01-28 13:04:09
问题 I'm new to C, and I think there may be an issue with pointers here. Any help would be appreciated! I have a linkedlist struct that looks like this: ll.h: #ifndef LLTEST_LL_H #define LLTEST_LL_H #include <stdlib.h> typedef struct _listNode { void *data; struct _listNode *next; } listNode; typedef struct { int logicalLength; int elementSize; listNode *head; listNode *tail; } linkedlist; typedef struct table { const char* name; size_t col_count; size_t length; } table; typedef struct db { const

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

I can call a function imported with dlsym() with a wrong signature, why?

故事扮演 提交于 2020-08-09 09:36:59
问题 host.cpp has: int main (void) { void * th = dlopen("./p1.so", RTLD_LAZY); void * fu = dlsym(th, "fu"); ((void(*)(int, const char*)) fu)(2, "rofl"); return 0; } And p1.cpp has: #include <iostream> extern "C" bool fu (float * lol) { std::cout << "fuuuuuuuu!!!\n"; return true; } (I intentionally left errors checks out) When executing host, “fuuuuuuuu!!!” is printed correctly, even though I typecasted the void pointer to the symbol with a completely different function signature. Why did this