void-pointers

Solution for "dereferencing `void *' pointer" warning in struct in C?

Hi, I was trying to create a pseudo super struct to print array of structs. My basic structures are as follows. /* Type 10 Count */ typedef struct _T10CNT { int _cnt[20]; } T10CNT; ... /* Type 20 Count */ typedef struct _T20CNT { long _cnt[20]; } T20CNT; ... I created the below struct to print the array of above mentioned ...

Disadvantages of using void* pointers in C

there are many drawbacks using void* in C(memory related, type related,efficiency wise ...). inspite of them we use them a lot for the flexibility they provide. list the disadvantages/drawbacks using void* (and preferd solution in C - if possible). EDIT: please go thru the follwoing link: http://attractivechaos.wordpress.com/2008/10/02...

Why is it impossible to have a reference-to-void?

Why is it impossible to have a reference to void? The only thing I found in the C++ Standard is this line, at 8.3.2.1 A declarator that specifies the type "reference to cv void" is ill-formed. Why is it that way? Why can't I write a "generic" function that accept a void&? Just to be clear, I have no useful application in mind whe...

The bounds on void-pointers in ANSI C89/ISO C90

Is there a way to portably determine the upper and lower bound on void-pointer values in ANSI C89/ISO C90? (I currently do not have a copy of the standard with me (I have one at home). Of course if void-pointer values are guaranteed to be unsigned this task is trivial (via sizeof(void *)); however, I cannot recall if this is guaranteed ...

Returning a void pointer to a constant object in C

I'm writing an access function which returns a pointer to an internal buffer and I'd like to hint to users of my function that they shouldn't update the object that's pointed to. A very contrived example would be: void myAccessFunc(bool string, void* p, size_t* len) { static const char* s = "aha!"; static const int i = 123; if (...

Concept of void pointer in C programming...

Is it possible to dereference the void pointer without type-casting in C programming language? Also, is there is any way of generalizing a function which can receive a pointer and store it in void pointer and by using that void pointer we can make a generalized function? for e.g. void abc(void *a, int b) { if(b==1) printf("%d...

How do I represent a void pointer in a PyObjC selector?

I'm wanting to use an NSOpenPanel for an application I'm designing. Here's what I have so far: @objc.IBAction def ShowOpenPanel_(self, sender): self.panel = NSOpenPanel.openPanel() self.panel.setCanChooseFiles_(False) self.panel.setCanChooseDirectories_(True) NSLog(u'Starting OpenPanel') self.panel.beginForDirectory...

Casting void pointers, depending on data (C++)

Basically what I want to do is, depending on the some variable, to cast a void pointer into a different datatype. For example (the 'cast' variable is just something in order to get my point across): void* ptr = some data; int temp = some data; int i = 0; ... if(temp == 32) cast = (uint32*) else if(temp == 16) cast = (uint16*) el...

Is it safe to delete a void pointer?

Suppose I have the following code: void* my_alloc (size_t size) { return new char [size]; } void my_free (void* ptr) { delete [] ptr; } Is this safe? Or must ptr be cast to char* prior to deletion? ...

void* to Object^ in C++/CLI

I am working on wrapping a large number of .h and .lib files from native C++ to Managed C++ for eventual use as a referenced .dll in C#. Some of the native C++ functions have a return type of void*. I am not sure how to handle this when I pass back the value to my calling code. For instance: if a C# app calls my dll wrapper, what do I ...

C: Function returning via void *

Coming from Java I'm confused by the use of Void allowing a return value in the following: void *emalloc(size_t s) { void *result = malloc(s); if (NULL == result) { fprintf(stderr, "MEMORY ALLOCATION FAILURE\n"); exit( EXIT_FAILURE ); } return result; } Is this returning a pointer to a chuck o...

objective c difference between id and void *

In objective C what is the difference between id and void *? Thanks. ...

If I have a void pointer, how do I put an int into it?

I have an array of arbitrary values, so I have defined it as an array of void pointers, so I can point to any kind of information (like int, character arrays, etc). However, how do I actually assign an int to it? Take for example these initializations: void* data[10]; int x = 100; My intuition would think this, but this gives a compi...

error: invalid conversion from 'void (*)(...)' to 'void (*)()'

Hi, having this problem on Mac with gcc 4.0.1 build 5370, XCode 2.5. The code snippet is: there is a declared function, the second parameter cause the problem: void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) calling it like this: typedef void (*FuncPtr)(); FuncPtr func = some_function_pointer; ffi_call(nul...

error: cast from 'void*' to 'int' loses precision

I have a function with prototype void* myFcn(void* arg) which is used as the starting point for a pthread. I need to convert the argument to an int for later use: int x = (int)arg; The compiler (GCC version 4.2.4) returns the error: file.cpp:233: error: cast from 'void*' to 'int' loses precision What is the proper way to cast this...

Implementing Win32 FileWrite

[DllImport("kernel32.dll", SetLastError=true)] public static extern unsafe bool WriteFile(IntPtr hFile, void* lpBuffer, uint nNumberOfBytesToWrite, out uint lpNumberOfBytesWritten, IntPtr lpOverlapped); I am implementing this through a Write(..) method with a signature: Write(IntPtr handleFile, void* bufferData, uint length){ ...

pointer arithmetic and the C# compiler

For the purpose of learning I recently looked at an existing assembly (using Reflector) that uses Win32 WriteFile. The implementation is: Write(IntPtr handleFile, void* bufferData, uint length){ void* buffer = bufferData while (length > 0) { uint wrtn; if (!WriteFile(handle, buffer, len, out wrtn, IntPtr.Zero)) { // Do some e...

Find out Type of C++ Void Pointer

Hello, I have a small question: how do I find out what type a C++ pointer is? I often use a small function in my console programs to gather input, which looks something like this: void query(string what-to-ask, [insert datatype here] * input) I would like to create a generic form, using a void pointer, but I can't cin a void pointer,...

C: deep copying - structure with a void pointer

Hi, I've got a following struct struct teststruct { int *a; void *data; }; Is it possible to do a deep copy of structure which contains a void pointer? I assume that I cannot tell how many bytes data pointer points to? So I cannot malloc specified number of bytes and do memcpy. Am I right? ...

void pointers: difference between C and C++

I'm trying to understand the differences between C and C++ with regards to void pointers. the following compiles in C but not C++ (all compilations done with gcc/g++ -ansi -pedantic -Wall): int* p = malloc(sizeof(int)); Because malloc returns void*, which C++ doesn't allow to assign to int* while C does. However, here: void foo(void...