HI, i am writing a program in which there are many do-while loops one inside the other... when i try compile this program... it gives me a error stating.."'{' scope stack overflow.." it point to braces i have used in DO-WHILE an IF statement... plss help me to solve this problem... THANKS...
we got this problem before. we got more memory for the computer and it was fixed.
Did you then take a visit to the compiler manual and check for specified limitations? http://www.keil.com/support/man/docs/c51/c51_xd.htm
A compiler is a finite thing so, clearly, you cannot just keep on nesting blocks indefinitely - there has not be some limit.
The 'C' standard specifies minimum limits - look up "Translation Limits" in the standard.
A compiler may, of course, exceed those minimum limits - for details, you must study the Manual for the particular compiler.
eg, http://www.keil.com/support/man/docs/c51/c51_xd.htm - titled, "Compiler Limits"
And, no - it has nothing to do with the amount of RAM in your PC!
I guess if you keep saying that to every post, you'll eventually hit one where it does just happen to be relevant.
This is not that case!
THANKS bro... i checked that link.. Is there any solution to overcome this without changing the code... or is there any alternative for this...
maximum 31 nested loops are executed... exceeding loops are ignored by the compiler... is there any solution to this.. plsss help... THANKS in regards
Yes - the solution is trivially simple. Write more readable code. Then you will not have 31 nested loops. Your code is messed up right now. Unmess it.
i dint got it.... what do u mean by readable code... u r right code is messed up...
You have done something wrong with your algorithm if you need 31 nested loops. Exactly what problem are you trying to solve that has so many nested loops?
When solving a problem that have an almost "unbound" number of variables and the algorithm should scan the full solution space, you don't do it by nesting loops. You do it by using data structures for the individual variables.
Think about a watch. It has hours and minutes and seconds. It loops 0..23 hours. Inside that it loops 0..59 hours. Inside that it loops 0..59 seconds. Just that there are not 3 nested loops. The code just looks like:
if (++seconds >= 60) { seconds = 0; if (++minutes >= 60) { minutes = 0; if (++hours >= 24) { hours = 0; } } }
Above code still shows nesting - but as you can see, the code can be trivially rewritten:
overflow = false; if (++seconds >= 60) { seconds = 0; overflow = TRUE; } if (overflow) { overflow = FALSE; if (++minutes >= 60) { minutes = 0; overflow = TRUE; } } if (overflow) { overflow = FALSE; if (++hours >= 24) { hours = 0; overflow = TRUE; } } if (overflow) { overflow = FALSE; if (++wdays >= 7) { wdays = 0; overflow = TRUE; } } if (overflow) { overflow = FALSE; ... }
Suddenly, an infinite number of loops can be handled in sequence without nesting.
Obviously, the above code, if handling a really silly number of loop variables, can be rewritten even more, where there is just a table of n variables and n overflow + reset values, so you have:
#define NELEM(a) (sizeof(a)/sizeof(*(a))) struct { unsigned val,restart,overflow; } variables[] = { {0,0,60}, // seconds {0,0,60}, // minutes {0,0,24}, // hours {0,0,7}, // wdays }; unsigned i; for (i = 0; i < NELEM(variables); i++) { if (++variables[i].val < variables[i].overflow) { // No overflow, so no carry to next level of variables. break; } else { variables[i].val = variables[i].restart; } }
THANKS for the details.... i'll modify my algo..... let u know afterwards..
You still haven't told us why you felt you had a need for such a huge number of nested loops.
spose u feel very clever?
give my m8 a break. hes just learning this stuff. u knew it all doin ur 1st project did u?
... feel very clever, but Per does not need to feel clever.
with that many nested loops the code IS messed up.
Of, course, it might be more politically correct to say "your excellent code has in your brilliance passed a silly limit set by the C standard. I do not know why the idiots that wrote the standard set a limit so low. Unfortunately, you will have to live with that limit ad reduce your loop count by the excess"
That, of course will leave the OP with code that, forever, is messed up.
A guy I know, refuse to look at code that, when correctly indented, has an identation level of more than 5. I think that is a good rule.
Erik
Data structures comes in very early.
But are you saying that beginners should not take one step back and consider "am I doing something wrong" when they get stuck by a compiler limitation, while thousands of professional developers do not get stuck by that same limitation?
Cleverer than you and your "m8"? Yes, obviously.
Well, how come we don't see you helping your "m8", instead of whining about the quality of advice he got? If you really believe that you can help this guy better than earlier responders, how come your "m8" had to even ask here in the first place?
Here's a suggestion: How about you two get together off-line, and actually help each other? I suggest you ask him to teach you less atrocious spelling than yours, in return.