|
Alex Ngai wrote:
and it will easily destory a program's structure,
and
Alex Ngai wrote:
a heavily-nested loop
So you want to protect the structure of your heavily nested loop code? Isn't that a bit of an oxymoron?
If you are actually concerned with program structure you might consider refactoring the code into a modern object oriented design that utilizes known patterns and techniques to solve simple structure problems like nested loops and 500 line if/elseif/switch statements.
But, that's just my opinion... I could be wrong.
Hate is not a family value
-pete
|
|
|
|
|
Thanks for all you guys's replies,
Unfortunately, at least 3-nested loop is a common practice:
while( )
{
for( ; ; ){
for( ; ; ){
}
}
}
Java does not have goto statement at all, but in order to jump out of a several-nested loop, Java has a smart extended break statement, it works like this:
first:{
second:{
third:{
System.out.println("Before break.");
if(condition)
break second;
System.out.println("This won't execute.");
}
}
System.out.println("after second block.");
}
As we see, it does the job of breaking out of a loop, and it won't have the problem of goto statment which will easily destroy a program's structure. Jave really is a great language, if only it was a system language like C/C++.
-----------------------------
C++ without virtual functions is not OO. Programming with classes but without dynamic binding is called "object based", but not "object oriented".
|
|
|
|
|
Alex Ngai wrote:
Unfortunately, at least 3-nested loop is a common practice:
Smoking crack is a common practice, but what does that have to do with Object Oriented Design?
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Seems to me, Java's "smart extended break statement" is nothing but a goto in disguise!
A disguised goto is worse than if it was naked!
Bikram Singh
|
|
|
|
|
At first: my expirience is, if it is going to get too complex, there ist some going wrong. Try to make subfunctions.
A good way to leave loops is to leave the whole funktion with "return" + exitcode.
Another option ist to use a central boolean which in every loop is checked.
Try this @ home. (B&B)
|
|
|
|
|
Well, the return statement only return back to the function calling point, that's breaking out of a function, not breaking out of a nested-loop.
The second option seems interesting, would you explain it a little more? I'm interested.
Thanks
-----------------------------
C++ without virtual functions is not OO. Programming with classes but without dynamic binding is called "object based", but not "object oriented".
|
|
|
|
|
Ravi Bhavnani wrote:
If you can't get yourself to use a goto ... you could instead throw an exception
I disagree. If goto is evil then throw ing an exception just to avoid using a goto is even worse! Which one is clearer to the person maintaining the code? Which one are you more likely to get wrong? Sometimes a goto is the right way to do something so long as it's well commented and isn't abused.
|
|
|
|
|
Hi,
I am writing a projet in C++ according to "CCSDS RECOMMENDEDATION FOR LOSSLESS DATA COMPRESSION" that is base on Rice coding algorithm. I am wondering if anybody has the source code that I can referce it.
Thanks a lot!
|
|
|
|
|
|
Hi, Ravi Bhavani,
Thank you for your information. I found this algorithm is different. What I am going to code is bassed on the NASA's Lossless Data Compression recommendation that modified the original Rice
code algorithm and seperated the algorithm into two parts: preprocessor and Adaptive Entropy Coder( http://www.ccsds.org//ccsds/). I searched throught the internet and found the corresponding source code named "SZIP", but I can not get any idea from there. I am wondering if you have heared
anything about this special Rice coding?
|
|
|
|
|
huffmancoding wrote:
I am wondering if you have heared
anything about this special Rice coding?
No, I haven't - sorry.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I placed a 'Reset' button on my property sheet right by the 'OK', 'Cancel', and 'Apply' buttons. I was wondering if anybody knew if there was a standard ID number for a 'Reset' button?
OK - IDOK - 1
Cancel - IDCANCEL - 2
Apply - ID_APPLY_NOW - 12321
Reset - ID_RESET??? - ???
I have currently defined a value of ID_RESET to 10055.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
I don't think so. The only "standard" ids I found in winuser.h were:
#define IDOK 1
#define IDCANCEL 2
#define IDABORT 3
#define IDRETRY 4
#define IDIGNORE 5
#define IDYES 6
#define IDNO 7
#if(WINVER >= 0x0400)
#define IDCLOSE 8
#define IDHELP 9
#endif /* WINVER >= 0x0400 */ /ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Thanks Ravi.
I also found those IDs. It is just that ID_APPLY_NOW is not in that list. It is in AfxRes.h along with the other property sheet buttons. So I was just wondering if the reset button was defined some where. I prefer to use standard IDs if there are any.
I will will leave it as it is.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Hello there
As a beginner in windows application programming I've run into a few problems - the most annoying being at a message posting procedure where the message never receives the intended recipient.
I've got a DLL which is intended for posting messages to an dialog at certain events. This posting are carried out by PostMessage. But the problem is that the message never arrives at the dialog. I've used Spy++ to check the handle of the intended recipient and the handle stored in the DLL, and they match. The return code of the PostMessage, is 0 = successful posting, but the dialog never receives the message (I've checked this with Spy++).
If I use HWND_BROADCAST as the first argument for PostMessage, my dialog receives the message correctly, thus i assume that my event handler in the dialog is correct.
What can be wrong?
Best regards
Thomas René Sidor
|
|
|
|
|
If the function fails, the return value is zero. To get extended error information, call GetLastError.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
I have used GetLastError, and the function itself does not fail. The problem is just that the message never arrives at the intended window.
Best regards
Thomas René Sidor
|
|
|
|
|
PostMessage 's return type is BOOL . 0 means FALSE , which means that the message was NOT posted. Again, use GetLastError to work out why.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
The method does not return 0. Therefore the use of GetLastError just tells that the command was succesfull.
|
|
|
|
|
McByte wrote:
The method does not return 0.
This is from your original post:
The return code of the PostMessage, is 0 = successful posting...
So what is the return value of PostMessage() ?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Damn, maybe I could be a little more clear on what I'm trying to say
My PostMessage does not return 0, that means that it does not fail. By using GetLastError() - i get Error code 0: Succesful...
Sorry for the mixup
|
|
|
|
|
I'm creating a console mode based project where there will be a neat looking menu system! What I'd love to know is, can I place the input focus from one part of the screen to another... e.g.
|--Menu---||-----Please input value----------|
|-Option 1-||--Input value:-------------------|
|-Option 2-||--You inputted..----------------|
|-Option 3-||--------------------------------|
|---focus--||--focus-------------------------|
|----------||--------------------------------|
As you can see - I'd like to be able to transfer focus from the menu to the input box (box shapes are created with ASCII characters and a heck of a lot of careful spacing! lol) whenever the user wants to by the press of a button.
Is this possible, and if so can someone please tell me! I'm using Microsoft Visual C++ Standard Edition. Any help would be well appreciated!!!
drjake
|
|
|
|
|
You mean, you want to move the cursor? SetConsoleCursorPosition .
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
How can i write a program and get it to start during the Windows boot process? Kind of like chkdsk.exe when you haven't shut your computer down properly, it gets displayed during bootup but XP hasn't fully loaded yet.
Kuniva
--------------------------------------------
|
|
|
|
|
The utility is called Autochk.exe. It is a "native application". This category lies somewhere between a device driver and a user mode app.
At boot time, the user mode-style apps cannot run since major window's components used for usermode(user.exe,gdi etc.) are not loaded.
in these cases, a native app is the only choice available. you need the xp/2000 ddk to make this kind of apps.
Notice that when you running autochk.exe after XP/NT has started, you get an error message "The autochk application cannot be run in Win32 mode".
To start such an app at boot time, see the registry key
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager and the value stirng value "BootExecute".
Usually, this value is "autocheck autochk *", but you can change that...
Bikram Singh
|
|
|
|