Click here to Skip to main content
15,907,910 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow do we cast void type Pin
luplup9-Feb-18 14:46
luplup9-Feb-18 14:46 
Hello,
I got problem trying converting type when the var is declared void in function.
How do you do these things !? for example casting short to int from void var (declared short at start)
And can we change a variable type without having to create new var !?

4 days im on, and i dont get solution without rewriting 50 "identical" functions just with changed type...
It's for that im looking to the void type.
Please help Smile | :)

C++
#include <stdio.h>

void calc(void *var) {
	//try convert short to int with new var
	int tmp = *(int*)var;
	printf("tmp: %i\n", tmp);//bad, must be 30002
	//try cast/convert original var
	*(int*)var += 30003;
}

void complexeShortToInt() {
	short int vInt2 = 30002;
	calc(&vInt2);
	printf("complexeShortToInt: %i\n", vInt2);//bad, must be 60005
}

/*void simpleShortToInt() {
	short int vInt = 30000;
	int vOut = (int)vInt;
	vOut += 30000;
	printf("simpleShortToInt: %i\n", vOut);//good
}*/

int main() {
	//simpleShortToInt();//good
	complexeShortToInt();//bad
	return 0;
}

AnswerRe: How do we cast void type Pin
Richard MacCutchan9-Feb-18 21:49
mveRichard MacCutchan9-Feb-18 21:49 
GeneralRe: How do we cast void type Pin
luplup10-Feb-18 7:15
luplup10-Feb-18 7:15 
GeneralRe: How do we cast void type Pin
Richard MacCutchan10-Feb-18 9:54
mveRichard MacCutchan10-Feb-18 9:54 
GeneralRe: How do we cast void type Pin
luplup10-Feb-18 11:35
luplup10-Feb-18 11:35 
GeneralRe: How do we cast void type Pin
Richard MacCutchan10-Feb-18 21:18
mveRichard MacCutchan10-Feb-18 21:18 
AnswerRe: How do we cast void type Pin
luplup12-Feb-18 8:00
luplup12-Feb-18 8:00 
GeneralRe: How do we cast void type Pin
jeron112-Feb-18 8:06
jeron112-Feb-18 8:06 
GeneralRe: How do we cast void type Pin
Richard MacCutchan12-Feb-18 8:24
mveRichard MacCutchan12-Feb-18 8:24 
GeneralRe: How do we cast void type Pin
Victor Nijegorodov10-Feb-18 10:01
Victor Nijegorodov10-Feb-18 10:01 
AnswerRe: How do we cast void type Pin
jschell10-Feb-18 6:40
jschell10-Feb-18 6:40 
GeneralRe: How do we cast void type Pin
luplup10-Feb-18 8:03
luplup10-Feb-18 8:03 
QuestionRe: How do we cast void type Pin
Victor Nijegorodov10-Feb-18 8:25
Victor Nijegorodov10-Feb-18 8:25 
GeneralRe: How do we cast void type Pin
luplup10-Feb-18 8:32
luplup10-Feb-18 8:32 
GeneralRe: How do we cast void type Pin
Richard MacCutchan10-Feb-18 9:58
mveRichard MacCutchan10-Feb-18 9:58 
GeneralRe: How do we cast void type Pin
jschell13-Feb-18 14:48
jschell13-Feb-18 14:48 
AnswerRe: How do we cast void type Pin
Victor Nijegorodov10-Feb-18 8:39
Victor Nijegorodov10-Feb-18 8:39 
GeneralRe: How do we cast void type Pin
luplup10-Feb-18 8:56
luplup10-Feb-18 8:56 
GeneralRe: How do we cast void type Pin
Victor Nijegorodov10-Feb-18 9:54
Victor Nijegorodov10-Feb-18 9:54 
AnswerRe: How do we cast void type Pin
Victor Nijegorodov10-Feb-18 10:05
Victor Nijegorodov10-Feb-18 10:05 
QuestionWhat is the two-finger scroll event (MFC app)? Pin
Alan Balkany8-Feb-18 17:18
Alan Balkany8-Feb-18 17:18 
AnswerRe: What is the two-finger scroll event (MFC app)? Pin
Randor 8-Feb-18 20:25
professional Randor 8-Feb-18 20:25 
AnswerRe: What is the two-finger scroll event (MFC app)? Pin
Richard MacCutchan8-Feb-18 22:48
mveRichard MacCutchan8-Feb-18 22:48 
Questionchange exe path Pin
Fedrer7-Feb-18 20:14
Fedrer7-Feb-18 20:14 
AnswerRe: change exe path Pin
Richard MacCutchan7-Feb-18 22:11
mveRichard MacCutchan7-Feb-18 22:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.