We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
i am facing error C141: syntax error near '}'
my program is given below:
#include<reg51.h> void main ( ) { int x; while (1) { P1 = 0x00 ; for (x=0 ; x<=5000 ; x++) P1 = 0xFF ; for (x=0 ; x<=5000 ; x++) } }
any one can help me how to solve it
This time, it's not due to a semicolon
Actually, that's exactly what it's due to. Fixing one missing semicolon would solve the issue the OP came here to ask about; while still yielding a royally silly program. Fixing the second missing semicolon would yield a typical, not totally silly implementation of what he most likely intended to do.
Well, technically, he can fix it with a semicolon or a {}, either solution works. That's how I did it but the semicolon is probably a better way to handle it.
In this case, we would have liked to see if the OP wrote code looking like (not too likely, since it gives a silly result):
void main ( ) { int x; while (1) { P1 = 0x00 ; for (x=0 ; x<=5000 ; x++) P1 = 0xFF ; for (x=0 ; x<=5000 ; x++) } }
Or (still same silly result):
or (showing misunderstanding of what ends a for() statement - or a copy/paste error):
The missing semicolon on the second for() loop indicates that the OP might have written the code as in the third example. So assuming the for() loop could handle itself, and that the P1 = 0xFF assignment would happen after the loop was done.
Or maybe the OP did write code like:
void main ( ) { int x; while (1) { P1 = 0x00 ; P1 = 0xFF ; } }
And then added the for() loops when noticing that the assigns directly after each other was too fast. And then did a copy/paste of a line with a missing ';' and couldn't understand why the first for() wasn't flagged as broken but the second was.
In the end - this is a specific case where the indentation would have told us more - even if we are able to read the one-liner.
Well technically, delays should be made with empty for() loops in the first place. The compiler is free to silently remove the empty loop, resulting in zero delay. Most compilers will remove that loop - at least with some optimization turned on.
I'll hand you a free "not" to fix the typo:
Well technically, delays should not be made with empty for() loops in the first place.
Thank you. That negation is quite important.
Per,
Remember earlier on I tailed a response with:
I'm sure you and your cohorts will have a view on what I have said, but remember that you did ask!
You asked, I answered. Then followed an extraordinary amount of bitching. Now look back at my original post. Was all that bitching really justified from that post or was it all from my second post? Remember, the one you asked for. Were you just looking to find fuel for the fire?
I see this response going badly . . .
"Was all that bitching really justified from that post or was it all from my second post? Remember, the one you asked for."
And if you read my posts - please show where I have bitched. I have given reasons why that pre tag matters even for this small code example.
And if you read my posts - please show where I have bitched.
I said "Then followed an extraordinary amount of bitching." I did not say the bitching was from you.
There were a small number of sensible responses, but would you deny that a few old regulars jumped on the bandwaggon? You know, those cohorts. Did you read some of the things they said? I see a few of those as not being just wrong, but also being outrageous. Nothing actually being said, just people looking for an excuse to say something, anything really. And some clearly just wanting to belittle.
Now I will not say any more on the matter. Maybe this post will trigger another flurry of outrageous comments. I may read them, to see if anything useful is added, but I'm not going to drawn in by any more 'what do you think about that' traps from you.
"[...] but I'm not going to drawn in by any more 'what do you think about that' traps from you."
So - what traps have I laid? Why you blame me if you get into troubles in a thread?
You worry about threads going down the drain. Still you use colored words like "sloppy", "traps" etc. Why am I suddenly thinking about kettles and black?
Tut-Tut.