Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Default Stack Size Pin
Richard MacCutchan11-Feb-18 7:10
mveRichard MacCutchan11-Feb-18 7:10 
GeneralRe: Default Stack Size Pin
ForNow11-Feb-18 7:13
ForNow11-Feb-18 7:13 
Questionsmoothing issue Pin
Member 1367132810-Feb-18 1:59
Member 1367132810-Feb-18 1:59 
AnswerRe: smoothing issue Pin
phil.o10-Feb-18 4:57
professionalphil.o10-Feb-18 4:57 
GeneralRe: smoothing issue Pin
Member 1367132810-Feb-18 5:04
Member 1367132810-Feb-18 5:04 
QuestionHow do we cast void type Pin
luplup9-Feb-18 14:46
luplup9-Feb-18 14:46 
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 
Surely it is not to put these sh*tty functions in my program, but it is to understand how i can handle this situation (so i reduced the code at max)
And the real situation of calc is to substitute the standard + - * / operations with "handle" of the overflow.
So for example a declared short int that excess the 32767 limit.

I know the type at start, but maybe it will produce an overflow later, and maybe with difficulty to detect.
So how we handle this situation !?

Here another more complete code, that can represent a var++;

C++
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

void calc(char *type, void *var1, char calc, void *var2) {

int tmp1 = *(int*)var1;//bad
int tmp2 = *(int*)var2;//bad
/*//this "work" but i want these short converted to int
short int tmp1 = *(short int*)var1;
short int tmp2 = *(short int*)var2;*/
printf("tmp1: %i\n", tmp1);
printf("tmp2: %i\n", tmp2);

int max, min;
unsigned int umax, umin;
short int overflow = 0;

if(strncmp(type, "short int", 9)==0) {
	max = SHRT_MAX;
	min = SHRT_MIN;
	}

if(calc == '+') {
	/*
	if(overflow == 0) {
		*(short int*)var1 = *(short int*)var1 + *(short int*)var2;
		}
	else{
		//addition not in short range, so cast the original var
		*(int*)var1 = tmp1 + tmp2;
		}
	*/
	}
}

int main() {
	short int vInt2 = 32767;//i dont know what is his real value at the moment, maybe in a loop
	short int vInt3 = 1;
	calc("short int", &vInt2, '+', &vInt3);
	printf("bad convert to int: %i\n", vInt2);
    return 0;
}


Edit: So if i dont use void, it seems i have to write lot of calc "identical" function for each type....

modified 10-Feb-18 14:26pm.

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 

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.