|
I found some runtime error in my solution
with the IDE: Visual Studio .Net 2003.
1st problem:
I inherited the STL class complex<_Ty>, and
add some members to the class. However,I found
the operator overloading didn't work well. I
follow the way <complex> did in the overloading
function:
return complex(x,y);
but the left side of the = lost many members.
and the builder would inevitably warn:
warning C4172: returning address of local variable or temporary<br />
'Complex.h(382) : while compiling class-template member function 'Complex<_Ty>::_Myt &Complex<_Ty>::operator *(const Complex<_Ty>::_Myt &)'<br />
with<br />
[<br />
_Ty=double<br />
]
Is there any suggestion? thanks!
2nd problem:
While debugging the code, I found SOME of the member
functions cannot be broke! but others CAN! and some
breakpoints would jump to the other functions while
debugging.
These break points would be marked with INFAMOUS white
question marks which said:
The breakpoint would not currently be hit. Invalid file line:353
I'd checked the configuration, it's set on debug mode.
Searching on the web but found no proper way.
Is there any suggestion? Thanks!
|
|
|
|
|
ytod wrote: warning C4172: returning address of local variable or temporary
you might have declared the operator overloaded funtion to return either the address od reference. Remove the reference or pointer in the return type of the function. If you paste the function here I will try to make it correct.
ytod wrote: While debugging the code, I found SOME of the member
functions cannot be broke! but others CAN!
the breakpoint cannot be put in some place where..
1. you have put a preprocessor switch so that, that part of code dosent get compiled and exists in the exe build
2. In an inline function
3. If control never reaches that point.
nave
|
|
|
|
|
|
I have some code that does (essentially) this:
...
char string[ 1024 ];
unsigned long length = 0;
strcpy( &string[ length ], ~arbitrary string 0~ );
length += strlen( &string[ length ] );
strcpy( &string[ length ], ~arbitrary string 1~ );
length += strlen( &string[ length ] );
...
strcpy( &string[ length ], ~arbitrary string n~ );
length += strlen( &string[ length ] );
...
This causes a 64-bit issue due to strlen returning size_t--64-bits on a 64-bit machine. There are two solutions:
solution 1 --
...
size_t length = 0;
...
solution 2 --
...
strcpy( &string[ length ], ~arbitrary string 0~ );
length += ( unsigned long )strlen( &string[ length ] );
...
In solution 1, 'length' becomes 64-bits and (presumably) more bits are being calculated.
In solution 2, 'length' remains 32-bits and (presumably) fewer bits are being calculated.
Assuming that this activity is happening at a high enough rate to matter, which approach would have better performance? Or does it not matter.
At present I do not have a 64-bit machine to test on.
-Obi Wan 2
|
|
|
|
|
I'd say best performance is with solution 1 in both 32 and 64 bit builds.
More bits aren't being calculated. size_t is 32 bits on 32-bit build and 64 bits on 64-bit
build. A 64=bit processor I presume will handle 64-bit integers just like a 32-bit processor
handles 32-bit integers. (*EDIT* ok technically more bits are being "calculated" but using
the same amount of machine instructions.)
In solution 2, on a 64-bit build, "length" stays 32-bit but all its uses are expecting 64-bit
so every time it's used there's a type conversion.
|
|
|
|
|
Mark:
Thanks.
It's true that in solution each use would cause a type conversion, but a trivial one. The processor could have a 32-bit load that forces the high order 32-bits to zero with no processing cost.
The more I think on it, the more I think there is no difference, but that solution 1 is more aesthetic.
-Obi Wan 2
|
|
|
|
|
Obi Wan 2 wrote: The more I think on it, the more I think there is no difference, but that solution 1 is more aesthetic.
I agree.
|
|
|
|
|
I have a Win32 console-based program which does this:
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
...
if( something failed )
{
nRetCode = 1;
}
return nRetCode;
} My customer is telling me that they are always getting errorlevel 0, and never getting errorlevel 1 upon failure.
I'm wondering, is return the proper way to return an errorlevel??? Or should I be using some other method? I seem to recall some sort of exit() function a million years ago from the old DOS days.
Thanks for any assistance!
|
|
|
|
|
chimera967 wrote: always getting errorlevel 0, and never getting errorlevel 1 upon failure
Are they sure the failure condition is ever being executed?
|
|
|
|
|
Maybe it's never failing!
AFAIK, you'll need to use exit() to work with ERRORLEVEL.
void _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nExitCode = EXIT_SUCCESS;
...
if( something failed )
{
nExitCode = EXIT_FAILURE;
}
exit(nExitCode);
}
|
|
|
|
|
That looks ok, the return value of main() is used as the process's exit code.
|
|
|
|
|
Well, im making a game, its great... except for this error, with this line:
Angle = asin((From->DestX - (Current->xPos /*Add offset*/))/SwingDistance);
In short that is:
Angle = asin((50 - 100)/65);
The numbers are just examples but you get the idea. Anyway, sometimes, it works perfectly, and its absolutley fine. Others, the angle gets set to -1#IND0 and my x,y co-ords get set to 0,0 as a result.
I debug it, check the values, put it into a calculator, and it works just fine.
So are there any ideas on this, has it come up before?
|
|
|
|
|
Wait, no, my foolish error with the calculator, it doesn't work.
Im just gonna put this down to inaccuracies when calculating the next position. I've sinced changed the method slightly, and all is good now.
|
|
|
|
|
I have to support French for an application.
All the resources of my application are stored in a DLL for French. when select default language, main resource is loaded and if select french, french dll of resource is loaded. Everything is fine as long as no custom controls are used.
I get a problem with custom control when load resource dll:
In old version, there is a control which managed by ActiveX Control, when i load resource dll (french) -> DONE:
CONTROL "",IDC_PREF_DIALOG_HIST,
"{E41EAFC4-F536-11CF-93A1-0000C0A61E5A}",WS_TABSTOP,7,7,
397,114
But in new version, this control is edit to Custom Control and manage by a new class (CHistogramCtl). when I use default language (English) => OK. But when I use french language (resource DLL), I could not load dialog which contain this control.
CONTROL "Custom2",IDC_PREF_DIALOG_HIST,"Histogram_Ctrl_Class",
WS_TABSTOP,7,7,397,118,WS_EX_CLIENTEDGE
Any suggestion will be helpful.
Thanks in advance,
Papais
Papais
|
|
|
|
|
How u create resources in French Language in VC++.
Thanks
Atool
Atool
|
|
|
|
|
I am using Visual C++ 6.0 MFC. I have gotten my secondary thread to work using AfxBeginThread(TestThread, this); but I don't want to use TerminateThread() based upon what I have been reading. When the secondary thread is spawned it may take 20 minutes for it to complete. I have a button on the tab page that spawned the thread that I want to use to 'Cancel Test' but I am confused as how to go about telling the thread to terminate itself cleanly. The psuedo code is as follows -
UINT C65602::TestThread(LPVOID Param)
{
C65602* device_type = (C65602*)Param;
device_type->TestThread();
return 0;
}
void C65602::TestThread()
{
HRESULT hr = CoInitialize(NULL);
pTests->pOutput->OpenExcelWorksheet();
pTests->RunTest(); // This may take 20 minutes
CoUninitialize();
AfxEndThread(0, TRUE);
}
void C65602::OnButtonBeginTest()
{
AfxBeginThread(TestThread, this);
}
void C65602::OnButtonCancelTest()
{
// I beleive this is where I want to tell the thread to terminate itself.
pTests->pGPIB->TurnOffDevice();
pTests->pOutput->SaveAndQuitExcel();
// or does it need to be here because of the Excel Automation im using?
AfxMessageBox("Test Canceled", MB_ICONINFORMATION);
CTabPage::OnCancel();
}
If anyone can push me in the right direction, throw me off the cliff.
Buck
|
|
|
|
|
You may find this[^] article (specifically the section "Pausing a Thread and Thread Shutdown") helpful.
/ravi
|
|
|
|
|
Unfortunately there is a documented bug having to do with the enum { Error, Running, Shutdown, Timeout } and the workarounds don't work.
Buck
|
|
|
|
|
Yep - Ravi's given you likely the best info you'll find, thanks also of course to 'The Flounder' - you must have logic within your thread that detects some sort of signal from the outside world and then acts on the signal, rather than trusting the OS to terminate the thread for you..
'g'
|
|
|
|
|
Unfortunately there is a documented bug having to do with the enum { Error, Running, Shutdown, Timeout } causing a fatal compiler error C1001 and the workarounds don't work.
Buck
|
|
|
|
|
The worker thread runs in your app's address space so a down-n-dirty method is to have it
periodically check a flag (maybe a bool variable somewhere) and if the flag is set stop doing
the worker thread stuff and exit. Set the flag false at the start, set it to true when the
user clicks cancel.
More elegant and thread safe is using an event. Pretty much the same as a flag except you'd
use WaitForSingleObject() (with a timeout == 0ms) periodically to check if the event has been
set. Create the event reset (non-signalled) at the start and set it when the user clicks
cancel.
Mark
|
|
|
|
|
You haven't given enough information. The pTests->RunTest(); // This may take 20 minutes line calls the function RunTest which is not shown. This code needs to be altered so it's interruptible.
Steve
|
|
|
|
|
Im in a property page and am trying to get a pointer
to the document. For some reason, it keeps giving me
a null pointer. I tried this:
CFrameWnd *pWndParentFrame = GetParentFrame();
CMultiScreenDoc *pDoc = NULL;
if( pWndParentFrame != NULL )
{
pDoc = (CMultiScreenDoc *)pWndParentFrame->GetActiveDocument();
}
and it doesnt work inside the property page. Any other
ideas any one else has will be greatly appreciated.
Sincerely,
Danielle Brina
|
|
|
|
|
If you do a quickwatch on pWndParentFrame in the debugger, is it pointing to the frame window you
are expecting (check its class )? Maybe you're not traversing up the window heirarchy far
enough...
Mark
|
|
|
|
|