|
You did not state what the problem is. What are you expecting from your code? What do you get instead that makes you say it is problematic?
"I'm neither for nor against, on the contrary." John Middle
|
|
|
|
|
Dear Friend.
The code works. But the output comes as stair steps. But, this is because of this sharpening .. and I want to alter . if you can give idea how to make the smoothing.
v2 is the velocity of second layer. and v1 is velocity of first layer.
maximum iterations is 10 with the percentage of threshold ..
problem is that it gives sharp stair stepping. while I want to make like smooth signal in output.
If you can guide.
|
|
|
|
|
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
#include <stdio.h>
void calc(void *var) {
int tmp = *(int*)var;
printf("tmp: %i\n", tmp); *(int*)var += 30003;
}
void complexeShortToInt() {
short int vInt2 = 30002;
calc(&vInt2);
printf("complexeShortToInt: %i\n", vInt2);}
int main() {
complexeShortToInt(); return 0;
}
|
|
|
|
|
Do not use void when you know the type that is to be operated on, it makes no sense. And your calc function would be better to return the calculated value, something like:
int calc(int var) {
int tmp = var + 30003;
return tmp;
}
I am not sure what the complexeShortToInt function, or the actual program, is supposed to do.
|
|
|
|
|
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++;
#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;int tmp2 = *(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 == '+') {
}
}
int main() {
short int vInt2 = 32767; 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.
|
|
|
|
|
You misunderstand the problem I'm afraid. Using a void pointer makes no difference, as your pointers will still point to different types. For example:
void calc(void* pvoid)
{
int value = *(int*)pvoid:
}
|
|
|
|
|
You too you misunderstood my problem i think, what you say will be handle by the type="float", and so ok a little "repeat" in the function but i find this better than 15 calc functions for each type.
So finally my real problem is for the "return value" that can have their type changed, its for that im thinking casting the void type that point to the initial variable, and i dont know if possible... im asking you.
So my real problem is this &vInt2 declared short int at start, that i want can change his type inside the function calc(), and without to have creating a new variable in the main scope.
Think that this vInt2 is a "main var" where i would do some operations, and automatically convert it to the right type if the initial type is not adapted.
So can we change a variable type without creating a new var !?
Finally if not possible, i can at least alert that this operation is bad for the initial type.
But i wanted to change the type to a bigger if possible, and so i can start with short int and handle more and more if necessary...
Edit: humm i spot a future problem that can break all when the type is changed so i would more think about how i can handle...
Finally my first interrogation come from: how i can protect my program about overflow automatically
So if you have more constructive suggestion...
modified 10-Feb-18 19:30pm.
|
|
|
|
|
luplup wrote: You too you misunderstood my problem i think, No, I understand completely; I am just saying that this is not the way to do it.
|
|
|
|
|
Ahah! finally got it... one var type changing, and one unique calc func, done WITH void* AND WITHOUT!
Sorry but i will keep it for me, as the main rule in this forum... and in any event, its not useful for you, and you well know the way how to do that, its tabou, all MVP devs know its dangerous to try making program without undefined behavior, and the best is to start making app without thinking to that... so 5 years after, you can (eventually) begin thinking to it when the problem appear and maybe recode all from scratch, and the best for you, i think you will love it, it is you can resell another time your sh*tty program because it's not a bug, its feature in your process...
Never i will go back in this forum, supposedly programming, the worst i ever seen... really you are not serious with your answers, you are trolling all the time on all the topics where you write something, but thank for me MacCutchan, you at least write me two lines of code, declaring a function and assigning variable, i dont know where i will be without your advanced experience... okay now i see from where come your 650 000 super value points... Whaou! you are really the best, without distinction! 9 times one of the best MVP helper... respect
I was already having a little preview of what can be an MVP before coming here, and finally it can be worse than i was thinking... so please dont delete my messages, i will keep it for souvenirs, and to show the real things about what is an supposedly "MVP programmer/engineer" and his mentality too... however if you del and so have something to hide, you have to delete this entire forum too, almost completely full of useless answers! now i well understand why it is a desert here...
Sorry for the possible real programmers that are shutting off all the time, but i dont know if there are some here.. no fact in the forum at least, and it seems all of you are "assisted" by fifty layers of abstraction/obscuration in your C++/MFC and then you think you are programmer...
So at NEVER!
|
|
|
|
|
luplup wrote: Never i will go back in this forum
Let's hope so.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
luplup wrote: Never i will go back in this forum Well, there will be many a dry eye here when you leave.
|
|
|
|
|
luplup wrote: Edit: So if i dont use void, it seems i have to write lot of calc "identical" function for each type....
But you still do not explain the main reason you want to use this "void*" method implementation!
modified 11-Feb-18 5:02am.
|
|
|
|
|
You are NOT using cast correctly.
You must NOT cast types to different types. Just take that rule as an absolute until you have been programming in C/C++ for about 5 years.
Besides other problems in your code you are taking a "short int" and treating it like an "int". That is wrong.
|
|
|
|
|
So please can you show me the right way to cast correctly
I dont want to "lose" my time during 5 years before start learning "real" programming.
So PLEASE show me a tiny code in the right direction, and i will pass 5 years studing it.
Do i have to use calloc/realloc for the int too ? like i used it for the char/struct array.
modified 10-Feb-18 14:19pm.
|
|
|
|
|
luplup wrote: Do i have to use calloc/realloc for the int too ? like i used it for the char/struct array.
Are you programming in C or C++?
|
|
|
|
|
|
Well it doesn't matter whether it is C or C++, what you are trying to do is a waste of time because it will never work. Get hold of a good book on C programming and learn these things properly.
|
|
|
|
|
luplup wrote: So please can you show me the right way to cast correctly
That would require a book.
You do it by understanding the data types that the pointer points to. What they represent, how they are represented in memory and what memory means in C (and computers in general) especially in relationship to the heap and the stack. And being very careful.
If you wish to learn in detail then write your own printf() function and test completely.
|
|
|
|
|
- Could you explain what are you trying to achieve using such type of very dangerous castings?
luplup wrote: void calc(void *var) {
int tmp = (int)var;
printf("tmp: %i\n", tmp);
(int)var += 30003;
}
The problem with this "casting" is the origin of the parameter passed to is short integer (the low WORD in Win32 environment).
But you are then trying to interpret it (somehow) as int causing to take into account the high WORD which contain garbage!
So what do you expect from the next manipulations with this garbage?
Well "4 days" for such a trial & error method is more than enough to understand (what you should have done for a couple of hours if you properly used a debugger) that such a "simple" casting in a real C/C++ code is very very dangerous and should be avoided!
|
|
|
|
|
1. The explain is in this answer Re: How do we cast void type - C / C++ / MFC Discussion Boards[^]
2. is this a valid cast short to int ?
int tmp = (short int)var;
Edit: im already suspecting my &vInt2 because it is not pointer, like maybe the void* would have, im here to ask you the right way for using this void "type"...
|
|
|
|
|
luplup wrote: is this a valid cast short to int ?
int tmp = (short int)var;
Yes, if the var was initialized from/as some short int value.
|
|
|
|
|
|
I'm trying to adapt an MFC custom grid control to handle two-finger touchpad vertical scrolls.
Looking through the Messages list in Class Wizard, I don't see anything that seems related to this. The control already has OnMouseWheel and OnVScroll handlers, and they work fine.
There doesn't seem to be any documentation on this. Can someone tell me the secret two-finger-scroll event, or point me in the right direction?
Thanks!
Alan
|
|
|
|
|
Hi,
Alan Balkany wrote:
There doesn't seem to be any documentation on this.
I think you are looking for the WM_GESTURE message[^].
Alan Balkany wrote: Looking through the Messages list in Class Wizard, I don't see anything that seems related to this. The control already has OnMouseWheel and OnVScroll handlers, and they work fine.
Just manually add the message handler... it's a standard window message.
Best Wishes,
-David Delaune
|
|
|
|
|
I think you will find that two-finger touchpad scrolls will generate standard scroll messages: WM_MOUSEWHEEL , WM_VSCROLL or WM_HSCROLL as appropriate. Should be easy enough to test.
|
|
|
|