void

why is this casting to void pointer valid?

天涯浪子 提交于 2019-12-11 01:38:35
问题 I'm debugging a program from a book. The program appears to work but I do not understand one line which I comment below. #include <pthread.h> #include <stdio.h> /* Compute successive prime numbers (very inefficiently). Return the Nth prime number, where N is the value pointed to by *ARG. */ void* compute_prime (void* arg) { int candidate = 2; int n = *((int*) arg); while (1) { int factor; int is_prime = 1; /* Test primality by successive division. */ for (factor = 2; factor < candidate; +

Why do we have to cast a void pointer to int or something else before printing the value in the memory whose address is in the pointer?

风流意气都作罢 提交于 2019-12-10 16:26:30
问题 I wonder why is it necessary to cast a void pointer to an int * or char * before printing the contents of the address in memory, even though we tell the printf() function how to interpret the data in memory? Let's say that we have the following code: int main (void) { void* c = malloc(4); printf("%d",*c); return 0; } Why it is not possible to do this? So to be clear my question is what is the reason for this being not possible? EDIT: After all the answers and research I am still not convinced

'void' type not allowed here (java) error [closed]

淺唱寂寞╮ 提交于 2019-12-10 12:22:53
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . Here is my code: public void start() { //If the gas tank and oil have more than nothing, and the transmission is in gear park, then the car can start if((gasTank.getGasLevel() > 0) && (engine.getOilLevel() > 0) &

From Java Object class to C++

◇◆丶佛笑我妖孽 提交于 2019-12-10 10:05:48
问题 I'm relative new to C++ and my background is in Java. I have to port some code from Java to C++ and some doubts came up relative to the Object Java's class. So, if I want to port this: void setInputParameter(String name, Object object) { ..... } I believe I should use void* type or templates right? I don't know what's the "standard" procedure to accomplish it. Thanks 回答1: It depends what you want to do with object . If you use a template, then any methods you call on object will be bound at

Conflicting types and previous declaration of x was here…what?

落花浮王杯 提交于 2019-12-09 16:26:13
问题 I've been teaching myself C for a few months when I have time, and I have run into a problem I am not sure how to fix. Specifically, when I try to compile this using gcc, I get: geometry.c:8: error: conflicting types for ‘trapezoid’ geometry.c:7: note: previous declaration of ‘trapezoid’ was here geometry.c:48: error: conflicting types for ‘trapezoid’ geometry.c:7: note: previous declaration of ‘trapezoid’ was here geometry.c:119: error: conflicting types for ‘trapezoid_area’ geometry.c:59:

How to delete void pointer?

本小妞迷上赌 提交于 2019-12-09 08:08:46
问题 Is there anything wrong when deleting an object like this in C++? MyCls* c = new MyCls(); void* p = (void*)c; delete (MyCls*)p; 回答1: This as written is legal. The cast back to MyCls* is critical. Without that, you will invoke undefined behavior--the MyCls destructor will not be called, and other problems may arise as well (such as a crash). You must cast back to the correct type. Also note that this can be complicated if multiple inheritance is involved and multiple casts are used. Your casts

Accessing void pointers in Python (using SWIG or something else)

試著忘記壹切 提交于 2019-12-08 21:03:32
I've been trying to use SWIG to wrap around a simple library that uses ioctl() to populate a structure like the following: struct data { header* hdr; void* data; size_t len; }; data is a pointer to a buffer, len is the length of that buffer. I'm unable to figure out how to convert data to a Python string (or array). Furthermore, I need a way to free that buffer in the destructor. Any suggestions are appreciated. Since you say "or something else" in the Q's title -- if you choose to use ctypes , you can represent a void* with c_void_p (one of ctypes' fundamental data types , and access

Differences between decltype(void()) and decltype(void{})

喜欢而已 提交于 2019-12-08 15:29:21
问题 This is a follow-up of the question: What does the void() in decltype(void()) mean exactly?. decltype(void()) compiles fine and what the void() means in this case is explained in the above mentioned question (actually in the answer). On the other side, I noticed that decltype(void{}) doesn't compile. What's the difference between them (in the context of a decltype at least)? Why doesn't the second expression compile? For completeness, it follows a minimal (not-)working example: int main() { /

Passing a void function as an argument to another function

╄→гoц情女王★ 提交于 2019-12-08 13:41:07
问题 I'm trying to pass a void function to another void function, unsuccessfully so far. So I created this function inside the class called ExitButton like this. ExitButton.h: class ExitButton{ void setup(void (*_setup)); }; Then I include that class into another class like this. ofApp.h: include "ExitButton.h" class ofApp : public ofBaseApp{ void update(); void setup(); StartButton *startButton; } So in my ofApp.cpp I want to call the update function like this: void ofApp::update(){ exitButton-

Android: from surfaceview back to the menu

坚强是说给别人听的谎言 提交于 2019-12-08 11:56:39
问题 I am making a simple game in which I draw a set of bitmaps on a Canvas on SurfaceView. Now in my main activity I have a LinearLayout where I have designed a button. In the onClick() of this button I write: setContentView(new surfaceviewclass(this)); it works fine. It opens the SurfaceView and I play the game etc. But I want to see the button again where I started from I mean when the game is over I want the menu to reappear.. I have already tried calling the void like main.menu(); but the app