void-pointers

“Un-casting” from (void *) and de-referencing to char array

独自空忆成欢 提交于 2019-12-12 03:47:19
问题 I have almost completed an homework assignment where I am required to use pthreads. I have figured out the pthreads. The only problem I have left is figuring out how to pass multiple arguments to threads through pthread_create(). I need to pass two chars to the thread. I have to cast them to (*void) to use with pthread_create(). I can pass them, but I can't figure out how to get the values from *parameter in the function. void *my_function(void *parameter) { /* ATTEMPT 1 - DOESN'T WORK */ /

Double linked list and void pointers [find method]

筅森魡賤 提交于 2019-12-12 01:06:34
问题 i wrote this double linked list with void pointers typedef struct list_el { void *data; struct list_el *prev; struct list_el *next; } list_el; typedef struct linked_list { int n_el; /*number of elements*/ list_el * head; /*pointer to the head*/ list_el * tail; /*pointer to the head*/ } linked_list; and i wrote those functions to handle with it. /*for list_el allocation*/ list_el * new_el ( void ) { return (list_el *) malloc(sizeof(list_el)); } /*list initialization*/ void init_list(linked

what is the practical use of void datatype and void pointer?

风格不统一 提交于 2019-12-11 19:18:47
问题 Void variable has nothing to do and also void pointer can only be pointed with casting. So void pointer is used when we actually don't know where and of which data type we want to point. But what is of void variable? Any practical example? 回答1: In C void can't be considered a data type, it is a keyword used as a placeholder in place of a data type to show that actually there is no data. For example consider the function void f(void); . Here the keyword void is used to mean the absence of any

C++ Builder 2009 - How to Determine if Control's Window is Visible

我与影子孤独终老i 提交于 2019-12-11 18:05:38
问题 I have a TWinControl and am trying to determine if the parent window is visible. I see TWinControl has a property of ParentWindow . The return type of ParentWindow is void * . So I'm curious if I must cast to a particular type, which would then give me access to check if the window is visible or not. Does anyone know the type I need to cast to, or another way to accomplish this? Additional Troubleshooting Notes, Part 1: I tried to get the ParentWindows class by: String parentWindowClassName =

C: How to access a function pointer stored in a void pointer (void *)?

大憨熊 提交于 2019-12-11 17:53:06
问题 Confused as to how one can access a function pointer stored in a void pointer (void *). Let's say you have this: void *functions[] = { &sqrt, // int ft_sqrt(int nb); &power, &logN, &factorial; }; // An array of void pointers, each storing a function pointer. If I wanted to access the sqrt function, my guess would be the following: (int (*)(int)) functions[0](x) But my guess is wrong: error: called object type 'void *' is not a function or function pointer So how would one access one of these

cast void* to classes with multiple inheritance

末鹿安然 提交于 2019-12-11 16:56:49
问题 I have an issue similar to the following: When is static cast safe when you are using multiple inheritance? multiple inheritance: unexpected result after cast from void * to 2nd base class but I really don't understand why it does not work, since I'm doing what is suggested (cast back to the original type). Also, templates are involved. I have a generic container of templated objects which I implement as a map of std::string IDs and void* : std::map<std::string, void*> mymap; The objects look

Passing to void** instead void* makes the compiler complain about types, why?

不羁岁月 提交于 2019-12-11 13:44:44
问题 I don't understand why the compiler warn me about passing an incompatible pointer type in this code: (in this context what are the difference between void * and void ** ) (I don't know if this make some difference but I am using gnu99 C version) void someFunc(void ** foo) { printf("%s\n", *foo); } int main() { char * text = "some text"; someFunc(&text); return 0; } and in this not void someFunc(void * foo) { printf("%s\n", foo); } int main() { char * text = "some text"; someFunc(text); return

Determining index from bsearch and lfind?

孤街浪徒 提交于 2019-12-11 08:26:14
问题 I'm trying to get the index of the element in the array after lfind and bsearch return the pointer to the element that it found. I have this so far: (char *) (found - cv->baseAddress); where found is the address of what the functions found, and the base address is the address of element 0. However, the compiler gives me this error: cvector.c:150:28: warning: pointer of type ‘void *’ used in subtraction cvector.c:150:4: warning: return makes integer from pointer without a cast What do I do?

Why don't you need to pass arguments to a qsort comparator function?

和自甴很熟 提交于 2019-12-11 08:12:03
问题 Code below taken from here. * qsort example */ #include <stdio.h> #include <stdlib.h> int values[] = { 40, 10, 100, 90, 20, 25 }; int compare (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int main () { int n; qsort (values, 6, sizeof(int), compare); for (n=0; n<6; n++) printf ("%d ",values[n]); return 0; } We have a compare function with parameters in its signature but when we call it in qsort no arguments are passed. How are the values of a and b passed to the function

Void pointer pointing to the same address

孤者浪人 提交于 2019-12-11 08:06:19
问题 Problem Void pointer to a cdef class is pointing to the same memory address without forcing the the python reference counter. Description I have a simple class that I want to store in a cpp vector by casting it to a void pointer. However, after printing the memory addresses the pointer is pointing to, it repeats after the second iteration, unless I force the reference counter to be increased by adding the new object to a list. Can somebody why the memory loops back without the reference