|
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.
|
|
|
|
|
Hello,
Actually I have changed the path of generation of exe from Debug to some other folder in Visual Studio 2012. Its generating in desired folder but its not able to launch it becuase it still looking the exe in Debug folder while launching.
Can you please help me to change the setting to run it.?
|
|
|
|
|
Go to the project properties settings, by right clicking the project name in Visual Studio. Select the "General" node under Configuration Properties, and change the "Output Directory" setting.
|
|
|
|
|
Thanks for reply.
This is what I am doing. Changing the output dir path will only change the creation of executable path.
But when I run it using ctrl+f5 it gives error because program is looking the exe in old(debug) folder
|
|
|
|
|
Hi,
For debugging this... right click on your visual studio solution and click 'Properties'. Go down to 'Build Events' and add a 'Pre-Build Event' and add the following two lines:
echo Debugging Path: $(TargetPath)
echo Executable Path: $(OutDir)$(TargetName)$(TargetExt)
These should always be the same. The paths will be in your build output.
Follow the instructions given by Richard MacCutchan and only change the 'Output Directory' located in the 'General' property page. I have a feeling that you mistakenly changed the 'Linker->Output File'. If I am correct... change it back to the default value of '$(OutDir)$(TargetName)$(TargetExt)' and follow his instructions.
Best Wishes,
-David Delaune
|
|
|
|
|
Go to the next node in Properties named Debugging, and change the Command entry from $(TargetPath) to the same path as you previously changed, followed by $(TargetFileName) ; you may need a backslash in front.
But all of this begs the question: why? You are just storing up trouble for the future by not sticking to the defaults.
|
|
|
|
|
I created a poll to find out what IDE developers use when working with C/C++.
I will publish the results as soon as I get a number of answers which is statistically relevant.
Feel free to comment here why you use a particular IDE after voting.
|
|
|
|
|
vim , because is the fastest one.
|
|
|
|
|
I would not consider Vim an IDE, but I use it for quick tests and while running this poll I found out a massive amount of developers use it!
|
|
|
|
|
Well, it is not.
Why did you include it, then?
Still it is one of my favourite development tools.
|
|
|
|
|
As I said many people use and consider it an IDE, especially when combined with several plugins.
Also, the poll is not about what I think/use, it's about what people use.
|
|
|
|