| | |
Int assigning problem
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2009
Posts: 8
Reputation:
Solved Threads: 0
I have this piece of code
And my problem is px doesn't get assigned.. it stays 0.. although in the debugger I can see all the values inside rect..
please help me
C++ Syntax (Toggle Plain Text)
// some function int px; void SomeFunction( void *dummy ) { ... RECT rect; GetWindowRect(hWnd, &rect); px = ((rect.right - rect.left) / 2) - 60; ... // Terminate thread _endthread(); }
And my problem is px doesn't get assigned.. it stays 0.. although in the debugger I can see all the values inside rect..
please help me
•
•
Join Date: Jul 2009
Posts: 8
Reputation:
Solved Threads: 0
http://msdn.microsoft.com/en-us/libr...97(VS.85).aspx
The values are numbers
c++ Syntax (Toggle Plain Text)
typedef struct _RECT { LONG left; LONG top; LONG right; LONG bottom; }RECT, *PRECT;
The values are numbers
•
•
•
•
I have this piece of code
C++ Syntax (Toggle Plain Text)
// some function int px; void SomeFunction( void *dummy ) { ... RECT rect; GetWindowRect(hWnd, &rect); px = ((rect.right - rect.left) / 2) - 60; ... // Terminate thread _endthread(); }
And my problem is px doesn't get assigned.. it stays 0.. although in the debugger I can see all the values inside rect..
please help me
The thing to take note of here is that px is currently declared as an int. Whereas rect.right and rect.left are both LONG/long variables.
Therefore if the result of your calculation is less than 1.0 (e.g. something like 0.43455664), then because px is an int, the calculated value will be truncated to 0.
Whereas if you alter px to be long, you'll get the actual calculated value (in my example 0.4345564).
I could be wrong, but that looks like the most obvious explanation to me!
oh, hang on.....Looking at that code, another thing strikes me as odd....
px is declared outside of the function, but used inside it..
That's probably your problem right there!
The px used in the function and the px outside of the function might not be the same variable, they might have different scope.
If you could post some more code, we might be able to determine whether or not this is the case!
Cheers for now,
Jas.
Last edited by JasonHippy; Aug 19th, 2009 at 11:33 am.
There are 10 types of people in this world.....
Those who understand binary .....
And those who don't!
Those who understand binary .....
And those who don't!
•
•
•
•
What about if you change px from int to long? Does that give you any differemt results?
The thing to take note of here is that px is currently declared as an int. Whereas rect.right and rect.left are both LONG/long variables.
Therefore if the result of your calculation is less than 1.0 (e.g. something like 0.43455664), then because px is an int, the calculated value will be truncated to 0.
Whereas if you alter px to be long, you'll get the actual calculated value (in my example 0.4345564).
The most likely explanation, as you suggested, is that px has also been declared locally and the OP is examining the global variable.
Try
::px = ((rect.right - rect.left) / 2) - 60;
I am assuming there is a local variable hiding the global.
::px = ((rect.right - rect.left) / 2) - 60;
I am assuming there is a local variable hiding the global.
I give up!
1) What word becomes shorter if you add a letter to it? [ Solved by : niek_e ]
2) What does this sequence equal to : (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
3) What is the 123456789 prime numer?•
•
Join Date: Jul 2009
Posts: 8
Reputation:
Solved Threads: 0
•
•
•
•
oh, hang on.....Looking at that code, another thing strikes me as odd....
px is declared outside of the function, but used inside it..
That's probably your problem right there!
The px used in the function and the px outside of the function might not be the same variable, they might have different scope.
If you could post some more code, we might be able to determine whether or not this is the case!
Cheers for now,
Jas.
this function is pretty long and I forgot that I have another px in it.
![]() |
Similar Threads
- int to string problem, need help quick (Java)
- Problem in C program (C)
- Converting a String to an int array (C++)
- int remainder problem! (C++)
- need help with tricky string modyfication (C)
- Please Help , Connection problem/dhcp/ip address (Networking Hardware Configuration)
- int problem (C++)
- Exercise using: unsigned char bcd(int n); (C)
Other Threads in the C++ Forum
- Previous Thread: Help Me Out Hamming Code
- Next Thread: Printing a diamond
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






