|
Right ...
Until your compiler says "initialization of variable declared when needed skipped by goto" ... then you go back to declaring them all at the top of your function
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
Blake Miller wrote: ...goto...
Hmm - this sounds like Linux driver code.
Or is someone else still using goto on a regular basis?
Anyway, if you jump over one part of your code and are missing variables later, your code is deeply flawed anyway.
Some variables do need to exist throughout the whole function - most are not.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
Well, I don't like to if( ...) statements nested 10 levels deep, and I am not fond of returns sprinkled throughout a function either. So ... goto FuncExit; in case of error. FuncExit is at bottom of funtion.
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
Blake Miller wrote: not fond of returns sprinkled throughout
For me, this is only a venial sin against the spirit of OO.
And a goto does make nothing clearer.
But when you only jump down to the return , you should miss no variables?
Sorry if I miss something obvious.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
We use goto a lot in functions that call other functions returning error codes.
suppose some pseudo-code like this...
if string pointer is null or string is empty
set error code
goto funcexit
if file can not be opened
set error code
goto funcexit
if file read error happens
set error code
goto funcexit
if memory allocation for structure fails
set error code
goto funcexit
FuncExit
if file opened
close file
return
-----------------
If you declare file handles, etc. as you need them, then the compiler will complain that the 'initialization' of the type was skipped by the goto.
In this case, the if statments would have only nested 5 levels deep ... ugh.
But in soeem of our more complex processing, there might be 15-20 function calls which might fail before the actual 'work' begins.
I WISH we were all OO - parts of this code base are untouched since the days of our company founders - back in 1989!
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
<sarcasm mode=true>
OMG :doh:
using a goto in c++, X|
why dont you use the functions <code>longjmp</code> and <code>setjmp</code> to write entirely incomprehensible code :laugh:
<sarcasm mode=false>
I known what you mean, because even in a switch you can have this problem.
but then again you could use { } to define the scope of that variable.
codito ergo sum
|
|
|
|
|
As long as you don't need the variable from the point of declaration all the way to end of function. Like a file handle you opened, you need it until you close the file.
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
The question was about the difference between using typedef and #define for defining types, not about variable usage. I would say to use whatever style is clearest and most appropriate for your situation - I don't dictate that certain styles are evil. I have no problems with using all the features of a language (including goto ...) if it is the most appropriate way of attacking a certain problem.
Besides, you seem to have misread that part of the question - that code sample is the expansion of the macro definition given before it...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi,
I'd like to create my own string class like CString class in MFC.
Kindly suggest me some good links regarding operator overloading & Unicode-ANSI.
Thanks in advance,
Sarvan AL
|
|
|
|
|
Well for me it's pretty strange that someone wants to write another string class... there are thousands of them flying around. I'm a fan of sticking to the standard one (especially with the boost additions).
But every one his own's.
For operator overloading I would consult "The c++ programming language" from Bjarne Stroustrup.
I can't give you a real pointer for looking up some information to Unicode - ANSI because you didn't specify it more.
Well.. maybe some thoughts.
All the label says is that this stuff contains chemicals "... known to the State of California to cause cancer in rats and low-income test subjects." Roger Wright http://www.codeproject.com/lounge.asp?select=965687&exp=5&fr=1#xx965687xx
|
|
|
|
|
|
Sarvan AL wrote: Kindly suggest me some good links regarding operator overloading & Unicode-ANSI.
you can try this class
CCOMString[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Anybody know how to/have any links to displaying images in widescreen aspect ratio with openGL?
When I die I'd like to go peacefully in my sleep like my father, not screaming in terror like his passengers!!!
|
|
|
|
|
Nobody? I assume I just need to change the clipping rects of the front and rear planes which would alter the frustum accordingly.
When I die I'd like to go peacefully in my sleep like my father, not screaming in terror like his passengers!!!
|
|
|
|
|
Hi all,
Sometimes I get runtime error in deleting the dynmically allocated object. I know the reasons. But how can I catch the exception during delete
Thanks in advance,
Sarvan AL
|
|
|
|
|
Most common type of problem is deleting an already deleted pointer.
You can check for null to avoid this...
if(pointer!=NULL)<br />
delete pointer;
Owner drawn
Jesus Loves
|
|
|
|
|
In C++ deleting a NULL pointer is a NOP - It is fine to do so.
You comment about a double delete is correct but only works if you NULL it after deleting it:
CSomeObject* pObj = SomeFunction();<br />
delete pObj;<br />
pObj = NULL;
delete pObj;
Steve
|
|
|
|
|
Thanks mate.
Owner drawn
Jesus Loves
|
|
|
|
|
Hello,
Did you try the following:
try
{
delete a;
}
catch( ... )
{
std::cout << "Caught exception!" << std::endl;
}
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
hi all,
I am using NI graph in some application .I need to get the height and width of the plot area of the graph like not the controls height and width its on the control some area will be used to plot the graph .I used the line below but its returning zero is there any alternative mathod
long lHeight = GraphPtr->GetPlotAreaImage().GetHeight();
"Men never do evil so completely and cheerfully as when they do it from religious conviction"
-Pascal
|
|
|
|
|
chethu665 wrote: NI graph in some application
I believe you are rfering to National Instrument Graphs.. if am right! there loads of graph samples present at there site! also they provide forums for same
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I have ported an application from vc to vc.net. While the application runs properly in vc it is crashing in release mode(debug is running correctly) in vc.net.
can any one pls. help what exactly could be the probable problem.
---Arun.
|
|
|
|
|
Hi,
I am lnking a static library in my application. On linking i am getting the following errors. I compiled my application with /MDd and /MD switches.
This is errors text that i am getting on building my application.
Created directory: release
cl -GX -TP -DNDEBUG -O2 -G6 -nologo -c -MDd -MD -verbose -W3 -DWIN32 -YX -Fprelease\Jsi.pch -Forelease/main.obj main.cpp
main.cpp
cl -GX -TP -DNDEBUG -O2 -G6 -nologo -c -MDd -MD -verbose -W3 -DWIN32 -YX -Fprelease\Jsi.pch -Forelease/SBjsiCreateResourceTest.obj SBjsiCreateResourceTest.cpp
SBjsiCreateResourceTest.cpp
cl -GX -TP -DNDEBUG -O2 -G6 -nologo -c -MDd -MD -verbose -W3 -DWIN32 -YX -Fprelease\Jsi.pch -Forelease/SBjsiDestroyResourceTest.obj SBjsiDestroyResourceTest.cpp
SBjsiDestroyResourceTest.cpp
cl -GX -TP -DNDEBUG -O2 -G6 -nologo -c -MDd -MD -verbose -W3 -DWIN32 -YX -Fprelease\Jsi.pch -Forelease/SBjsiInitTest.obj SBjsiInitTest.cpp
SBjsiInitTest.cpp
cl -GX -TP -DNDEBUG -O2 -G6 -nologo -c -MDd -MD -verbose -W3 -DWIN32 -YX -Fprelease\Jsi.pch -Forelease/SBjsiShutDownTest.obj SBjsiShutDownTest.cpp
SBjsiShutDownTest.cpp
link -nodefaultlib:msvcrt.lib -nodefaultlib:msvcrtd.lib -nodefaultlib:libcd.lib -nologo -machine:I386 -incremental:no -fixed:no -MAP kernel32.lib user32.lib advapi32.lib UnitTestDriver.lib -out:release\Jsi.exe -release -libpath:"d:\openvxi\lib" VXIlog.lib VXIjsi.lib UnitTestDriver.lib xerces-c_2.lib -libpath:"d:\openvxi/lib" -libpath:"c:\xerces-c-src_2_6_0/lib" -libpath:"d:\openvxi/test/lib" @C:\DOCUME~1\050343\LOCALS~1\Temp\nma01800.
UnitTestDriver.lib(success.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler
UnitTestDriver.lib(failure.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler
SBjsiShutDownTest.obj : error LNK2001: unresolved external symbol ___CxxFrameHandler
UnitTestDriver.lib(testresult.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler
UnitTestDriver.lib(vostring.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler
UnitTestDriver.lib(test.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler
main.obj : error LNK2001: unresolved external symbol ___CxxFrameHandler
SBjsiCreateResourceTest.obj : error LNK2001: unresolved external symbol ___CxxFrameHandler
SBjsiDestroyResourceTest.obj : error LNK2001: unresolved external symbol ___CxxFrameHandler
SBjsiInitTest.obj : error LNK2001: unresolved external symbol ___CxxFrameHandler
UnitTestDriver.lib(success.obj) : error LNK2001: unresolved external symbol __except_list
UnitTestDriver.lib(failure.obj) : error LNK2001: unresolved external symbol __except_list
SBjsiShutDownTest.obj : error LNK2001: unresolved external symbol __except_list
UnitTestDriver.lib(testresult.obj) : error LNK2001: unresolved external symbol __except_list
UnitTestDriver.lib(vostring.obj) : error LNK2001: unresolved external symbol __except_list
UnitTestDriver.lib(test.obj) : error LNK2001: unresolved external symbol __except_list
main.obj : error LNK2001: unresolved external symbol __except_list
SBjsiCreateResourceTest.obj : error LNK2001: unresolved external symbol __except_list
SBjsiDestroyResourceTest.obj : error LNK2001: unresolved external symbol __except_list
SBjsiInitTest.obj : error LNK2001: unresolved external symbol __except_list
UnitTestDriver.lib(testresult.obj) : error LNK2001: unresolved external symbol _atexit
UnitTestDriver.lib(testregistry.obj) : error LNK2001: unresolved external symbol _atexit
UnitTestDriver.lib(test.obj) : error LNK2001: unresolved external symbol _atexit
SBjsiCreateResourceTest.obj : error LNK2001: unresolved external symbol _atexit
SBjsiDestroyResourceTest.obj : error LNK2001: unresolved external symbol _atexit
SBjsiInitTest.obj : error LNK2001: unresolved external symbol _atexit
SBjsiShutDownTest.obj : error LNK2001: unresolved external symbol _atexit
UnitTestDriver.lib(success.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
UnitTestDriver.lib(failure.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
SBjsiCreateResourceTest.obj : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
SBjsiDestroyResourceTest.obj : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
UnitTestDriver.lib(testresult.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
UnitTestDriver.lib(vostring.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
LINK : error LNK2001: unresolved external symbol _mainCRTStartup
UnitTestDriver.lib(testresult.obj) : error LNK2001: unresolved external symbol __imp__exit
UnitTestDriver.lib(vostring.obj) : error LNK2001: unresolved external symbol __imp__sprintf
UnitTestDriver.lib(success.obj) : error LNK2001: unresolved external symbol __imp__sprintf
UnitTestDriver.lib(failure.obj) : error LNK2001: unresolved external symbol __imp__sprintf
UnitTestDriver.lib(vostring.obj) : error LNK2001: unresolved external symbol __fltused
UnitTestDriver.lib(test.obj) : error LNK2001: unresolved external symbol __purecall
msvcprt.lib(delop_s.obj) : error LNK2001: unresolved external symbol _free
release\Jsi.exe : fatal error LNK1120: 10 unresolved externals.
Where UnitTestDriver.lib is the static library that we built.
Please do let me know what i need to do.
Regards, Eswari
Subramanyeswari
|
|
|
|
|
-MDd and -MD are mutually exclusive flags - you can't specify both of them. Use -MDd to specify a multithreaded debug build, and -MD to specify a multithreaded release build.
If you use -MDd, you'll need to ensure you're linking against MSVCRTD.LIB , -MD requires MSVCRT.LIB
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Thank for your reply Ryan,
But it did not work. This is the output i got. As you suggested i changed my make as:
# /Od disable optimizations
CFLAGS_DEBUG = -D_DEBUG -Od -Zi -Fd$(TARGET).pdb -MDd
# /O2 optimize for speed
# /G6 generate code for Pentium Pro
CFLAGS_RELEASE = -DNDEBUG -O2 -G6 -MD
..
And i compiled taking release option and this is the output. What i am missing here.
Created directory: release
cl -GX -TP -DNDEBUG -O2 -G6 -MD -nologo -c -W3 -DWIN32 -YX -Fprelease\Jsi.pch -Forelease/main.obj main.cpp
main.cpp
cl -GX -TP -DNDEBUG -O2 -G6 -MD -nologo -c -W3 -DWIN32 -YX -Fprelease\Jsi.pch -Forelease/SBjsiCreateResourceTest.obj SBjsiCreateResourceTest.cpp
SBjsiCreateResourceTest.cpp
cl -GX -TP -DNDEBUG -O2 -G6 -MD -nologo -c -W3 -DWIN32 -YX -Fprelease\Jsi.pch -Forelease/SBjsiDestroyResourceTest.obj SBjsiDestroyResourceTest.cpp
SBjsiDestroyResourceTest.cpp
cl -GX -TP -DNDEBUG -O2 -G6 -MD -nologo -c -W3 -DWIN32 -YX -Fprelease\Jsi.pch -Forelease/SBjsiInitTest.obj SBjsiInitTest.cpp
SBjsiInitTest.cpp
cl -GX -TP -DNDEBUG -O2 -G6 -MD -nologo -c -W3 -DWIN32 -YX -Fprelease\Jsi.pch -Forelease/SBjsiShutDownTest.obj SBjsiShutDownTest.cpp
SBjsiShutDownTest.cpp
link -nodefaultlib:msvcrt.lib -nodefaultlib:msvcrtd.lib -nodefaultlib:libcd.lib -nologo -machine:I386 -incremental:no -fixed:no -MAP kernel32.lib user32.lib advapi32.lib UnitTestDriver.lib -out:release\Jsi.exe -release -libpath:"d:\openvxi\lib" VXIlog.lib VXIjsi.lib UnitTestDriver.lib xerces-c_2.lib -libpath:"d:\openvxi/lib" -libpath:"c:\xerces-c-src_2_6_0/lib" -libpath:"d:\openvxi/test/lib" @C:\DOCUME~1\050343\LOCALS~1\Temp\nma01888.
UnitTestDriver.lib(success.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler
UnitTestDriver.lib(failure.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler
SBjsiShutDownTest.obj : error LNK2001: unresolved external symbol ___CxxFrameHandler
UnitTestDriver.lib(testresult.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler
UnitTestDriver.lib(vostring.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler
UnitTestDriver.lib(test.obj) : error LNK2001: unresolved external symbol ___CxxFrameHandler
main.obj : error LNK2001: unresolved external symbol ___CxxFrameHandler
SBjsiCreateResourceTest.obj : error LNK2001: unresolved external symbol ___CxxFrameHandler
SBjsiDestroyResourceTest.obj : error LNK2001: unresolved external symbol ___CxxFrameHandler
SBjsiInitTest.obj : error LNK2001: unresolved external symbol ___CxxFrameHandler
UnitTestDriver.lib(success.obj) : error LNK2001: unresolved external symbol __except_list
UnitTestDriver.lib(failure.obj) : error LNK2001: unresolved external symbol __except_list
SBjsiShutDownTest.obj : error LNK2001: unresolved external symbol __except_list
UnitTestDriver.lib(testresult.obj) : error LNK2001: unresolved external symbol __except_list
UnitTestDriver.lib(vostring.obj) : error LNK2001: unresolved external symbol __except_list
UnitTestDriver.lib(test.obj) : error LNK2001: unresolved external symbol __except_list
main.obj : error LNK2001: unresolved external symbol __except_list
SBjsiCreateResourceTest.obj : error LNK2001: unresolved external symbol __except_list
SBjsiDestroyResourceTest.obj : error LNK2001: unresolved external symbol __except_list
SBjsiInitTest.obj : error LNK2001: unresolved external symbol __except_list
UnitTestDriver.lib(testresult.obj) : error LNK2001: unresolved external symbol _atexit
UnitTestDriver.lib(testregistry.obj) : error LNK2001: unresolved external symbol _atexit
UnitTestDriver.lib(test.obj) : error LNK2001: unresolved external symbol _atexit
SBjsiCreateResourceTest.obj : error LNK2001: unresolved external symbol _atexit
SBjsiDestroyResourceTest.obj : error LNK2001: unresolved external symbol _atexit
SBjsiInitTest.obj : error LNK2001: unresolved external symbol _atexit
SBjsiShutDownTest.obj : error LNK2001: unresolved external symbol _atexit
UnitTestDriver.lib(success.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
UnitTestDriver.lib(failure.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
SBjsiCreateResourceTest.obj : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
SBjsiDestroyResourceTest.obj : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
UnitTestDriver.lib(testresult.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
UnitTestDriver.lib(vostring.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
LINK : error LNK2001: unresolved external symbol _mainCRTStartup
UnitTestDriver.lib(testresult.obj) : error LNK2001: unresolved external symbol __imp__exit
UnitTestDriver.lib(vostring.obj) : error LNK2001: unresolved external symbol __imp__sprintf
UnitTestDriver.lib(success.obj) : error LNK2001: unresolved external symbol __imp__sprintf
UnitTestDriver.lib(failure.obj) : error LNK2001: unresolved external symbol __imp__sprintf
UnitTestDriver.lib(vostring.obj) : error LNK2001: unresolved external symbol __fltused
UnitTestDriver.lib(test.obj) : error LNK2001: unresolved external symbol __purecall
msvcprt.lib(delop_s.obj) : error LNK2001: unresolved external symbol _free
release\Jsi.exe : fatal error LNK1120: 10 unresolved externals
Please help me..
Regards
|
|
|
|