|
What is wrong with the following?
long value;
value &= 0xFFFF;
|
|
|
|
|
tom groezer wrote: 0xFFFF
Only covers 16 bits, long is 32 bits so it ought to be 0xFFFFFFFF
Since the statement before is long value; , who knows what it is initialized to.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
"value" isn't initialized before masking the low-order 16 bits.
Otherwise, nothing.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
also...be careful with the definition of "long". We get used to it being a 32 bit integer when
Win32 programming but the language definition does NOT require a long to be 32 bits.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
Mark Salsbery wrote: language definition does NOT require a long to be 32 bits.
That is true. Doing a quick sizeof doesn't hurt to do from time to time. :->
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
"value" is uninitialized. Givce it a value of 0, and you should be fine.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Thnkx a lot for "floating point comparisions".............
Does this mean IEEE32/64 arent good enough to store FPs accurately AND wat when we use the same number to print on screen......i mean how is that FP printed accurately?
Spread wat u Know!
|
|
|
|
|
Read What Every Computer Scientist Should Know About Floating Point Arithmetic[^].
A binary floating-point number can only store numbers that are sums of powers of two. The digits to the right of the point are sums of negative powers of two. Just as 1/3 is not accurately representable in decimal (0.33333.... etc), 1/5 is not accurately representable in binary. The more operations you perform on a limited precision representation, the more representation error builds up. That's why it's rarely a good idea to directly compare two floating point numbers.
I don't think there are any values representable in binary that are not representable in decimal, because two divides evenly into ten. However, when displaying a floating point result, it's common to only show some decimal places, displaying a rounded result.
If you want decimal values, with a fixed decimal point, to be stored and computed accurately, you should use a scaled integer. This is not supplied by standard C++ so you'll have to find an implementation, e.g. here[^].
|
|
|
|
|
Is there anything wrong with this program
T *p = 0;
delete p;
Something to do with overloaded delete operator?
|
|
|
|
|
No.
i don't know anything about T so it's impossible to say if an overloaded operator is involved.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
Hello,
I would suggest that you don't need the delete.
If your example looked like this:
int* inptr = NULL;
but if you allocate memory with the keyword 'new'
then you should 'delete' it form the heap.
So you can remember new and delete belong together.
Greetz
|
|
|
|
|
The whole thing is bad form.
First, a pointer should be set to NULL, not 0. This is more for practical readability than anything else.
Second, you should not delete a pointer that hasn't been allocated. I know, modern compliers let you do it, and it's supposed to be safe, but it's bad practice.
Lastly, your variable names quite frankly suck.
The whole thing should read like this:
T* p = NULL;
if (p != NULL)
{
delete p;
p = NULL;
}
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hello all ,
i have made 4 ui threads in my application and various instances of these threads are running at same time. There may be 100 or 200 instances running.
what i want to knw is how can i close all these thread together rather closing them one by one.
Can anybody help me in this....
Thanks in advance
|
|
|
|
|
|
I am developing a software in which,
each menu opens a panel(dialog) and user is suppose to not access
the other menu ,unless he closes dialog. So by the time one panel is active ,it is required to deactivate entire menubar.
I am using SDI and modified default menu bar for same.
I was not able to find any method to directly deactivate.
But whatever I found that is also not working.
My entire toolbar I was able to disable,but not menu bar.
Also I like to know how to disable individual button of toolbar.
void CMainFrame::OnAddCustomer()
{
CToolBarCtrl& ctb = m_wndToolBar.GetToolBarCtrl();
ctb.EnableWindow(FALSE);
ctb.PressButton(ID_ADD_CUSTOMER,true);
CMenu* cmu = this->GetMenu();
UINT ui = cmu->EnableMenuItem(ID_ADD_CUSTOMER,MF_DISABLED);
|| ART OF LIVING ||
|
|
|
|
|
You could use MFC command enablers. This should enable/disable both toolbar and menu items...
afx_msg void OnUpdateDbconnect(CCmdUI* pCmdUI);
...
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_UPDATE_COMMAND_UI(ID_ADD_CUSTOMER, OnUpdateAddCustomer)
END_MESSAGE_MAP()
...
void CMainFrame::OnUpdateAddCustomer(CCmdUI* pCmdUI)
{
if (...some condition...)
pCmdUI->Enable(FALSE);
else
pCmdUI->Enable(TRUE);
}
See the ON_UPDATE_COMMAND_UI/ON_UPDATE_COMMAND_UI_RANGE macros in the docs.
You can also disable thw main window
EnableWindow(FALSE);
That's what MFC does to simulate modal dialogs.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
I want to control the avi write action by query the IAMStreamControl interface of input pin in pAviMux, see below:
IAMStreamControl *pSC = NULL;
hr = pMuxPin01->QueryInterface(IID_IAMStreamControl, (void **)&pSC);
hr = pSC->StartAt(&rtStart, 0); //rtStart = 3 seconds
hr = pSC->StopAt(&rtStop, FALSE, 0); //rtStop = 9 seconds
hr = pMediaControl->Run();
when I set the parameter of StartAt() as NULL, it works OK,
the pMuxAvi stop the writing at rtStop time. however,
when I give a rtStart parameter to StartAt() function,
the pMuxAvi write a corrupt avi file which is only 127kb in size.
what's wrong with the StartAt() function? please help.
-- modified at 6:02 Saturday 14th July, 2007
|
|
|
|
|
hello
i like to recieve data from digitizer or a tablet connected to my computer through usb .
how can i do that.
these data come from moement of pen over the tablet , like speed of writing, depth, degree of the pen , and others
|
|
|
|
|
Normally, you should have a driver that is supplied with this device. To 'communicate' with this device from your code, you need to get a handle to this driver (using CreateFile) and then you will be able to use ReadFile and WriteFile operation. You probably want to do some specific things with the driver in which case you can call DeviceIOControl and supply some specific code.
|
|
|
|
|
Thank you for your help.
i well try to do what you tell me.
i installed the driver but i see there are 4 or more DLL files.
can you tell me how can i know the suitable file among them for me to read from it the data
if you have other advices in using these commands (FreateFile ReadFile/WriteFile, DeviceIOControl)write to me i
|
|
|
|
|
Hi,
I can able to connect Ms_word to VC++ MFC application and can write text in that. But I want to know how can i insert image in ms-word using MFC. If you help me, it will be great.
Actually i refered
http://support.microsoft.com/kb/q238611/[^] this site to embed Ms-word to MFC
|
|
|
|
|
How can i import jpeg images into workspace of an application?
|
|
|
|
|
Right click on the Resource View of your project and select Add Resource and click Import button after select your image file(jpg) you see a other window "Custom Resource Type" you must type a name for this resource and click ok.
|
|
|
|
|
|
A char is a single character. You'd be better off storing the file name in a char array.
|
|
|
|