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
Yes we can.
But why can you not use the correct formatting so we get to see a properly intended source code? Didn't you check the information directly above the message input box?
Back to your - very hard to read - code: What should a for loop do if you have nothing for it to do? Can a for loop be totally without statement - what does your C programming book say?
Another thing - what use is it to make 5001 assigns of P1 = 0xFF directly after each other? Exactly how do you think P1 = 0xFF interacts with the for loop?
Back to your - very hard to read - code
Not very nice but you really think it's hard to read? It's virtually a one liner.
In this case, more important than the "pre" thing is proper indentation.
You're really not getting it. That "pre thing" is needed to to do keep that indentation of pasted source code!
I.e. if you copy-paste some nicely formatted code into the new-message window, but ignore putting it into "pre" tags, what you get is exactly that kind of all-in-one-line, unindented mess that the original posting was.
You didn't seriously believe that all those nonsensical, unformatted source code examples weg get in here originally looked that way before being copy-pasted into the forum, did you?
Chill out, man. You're heart is going to explode from high blood pressure over a really tiny misunderstanding . . .
I don't know what the person put in originally. For all you know, he does write all his code in one line. I also don't know how these forums handle those "pre" things because I usually put in pre-formatted code and use those stupid "pre" thingies, as the forum specifies. I didn't try putting in formatted and unformatted code, just to understand how these forums handle it.
I could swear, some of you guys go LOOKING for arguments and I just don't get it. Pick your battles. You can find something wrong with just about every post if you look at them intently enough. Is it really that important to you?
Congrats, I was wrong. You win the internets. Feel better?
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.
I don't know what the person put in originally.
You see, that's the difference: we actually do, to a high level of certainty, from experience that you apparently don't have.
I also don't know how these forums handle those "pre" things because I usually put in pre-formatted code and use those stupid "pre" thingies, as the forum specifies. I didn't try putting in formatted and unformatted code, just to understand how these forums handle it.
Yet you took it upon yourself to accuse us of inappropriate comments, and of concentrating on little things while ignoring the big issues. If you start your end of a conversation like that while the well-known facts contradict your position, you can't seriously expect to be congratulated for your efforts.
Chill out, man. You're heart is going to explode from high blood pressure over a really tiny misunderstanding First I do not think Hans-Bernhard is at the level of an exploding hart, he is just annoyed about the people that want help but do not have the courtesy to make it as easy as possible to help them. Second, nobody has run this post because of "a really tiny misunderstanding" but instead beacuse of your need to comment on lack of "political correctness". If you want help, welcome, if you want to *** about "political correctness" please stay away. Many of us are willing to help; however, we help as we see fit not as some bleeding heart think we should.
Erik
What was wrong with my response? He has three posts nitpicking about how people should post while adding nothing to what is actually wrong with the original code and I'm the ass? I'm not getting on his case for political correctness purposes (I get that many people don't put in enough effort, it's well documented in the 10 posts before his), I'm on his case for picking fights.
Why am i getting grief? Because I'm not just sitting there and taking the shots he throws at me because he's an "experienced" programmer and he assumes I'm not because I don't know the inner workings of these particular forums?
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.
What was wrong with my response? That you raised an insignificat issue after the OP had his question answered
He has three posts nitpicking about how people should postsure, since you raised the issue while adding nothing to what is actually wrong with the original code sure, that was answered in the first post, then after your 'response' it became about your nitpick and I'm the ass? you said it
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.
What was wrong with my response?
Partly, that it looked and felt so much like "Trever Morgan"'s earlier contribution that I mixed you two guys up. Sorry for that. It was hime who complained about inappropriate replies, not you.
He has three posts nitpicking about how people should post while adding nothing to what is actually wrong with the original code
What, and you didn't?
If you bothered to actually look, you would find that I only responded to posts by you and others that had already gone down that route, and I did so in order to correct some factual mistakes in those posts.
and I'm the ass?
Nobody said anything like that.
... nor that. The latter you said yourself, but nobody disclaimed your experience as a programmer because of it.
So let's see, you're making up things I'm supposed to have done to you, and I'm the one picking fights here? Really?
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.
"He has three posts nitpicking about how people should post while adding nothing to what is actually wrong with the original code and I'm the ass?"
Who is "he"? I have several posts commenting on how people should post. But I also have other information in the posts - if the original post had enough contents to make it possible/meaningful.
Thank you. That negation is quite important.
When it comes to compilers (and circuits, for that matter) the "little things" really do matter.
Well, technically, the little things that matter to the compiler are the things that matter to the compiler. Formatting tags useful for posts here are not relevant to the compiler, therefore they do not matter to the compiler.
But pointing out all the little things without spotting the big thing staring you in the face is just plain unforgivable - Surely you would not disagree?
You missed the point entirely!
The point is that the inability to follow simple, clearly-stated instructions is symptomatic of a fundamental problem in the OP's approach.
I think their point is, yes, if that was the only person to ever post here and they only had to answer that one question, it's readable.
But since many people come here asking for help with bad formatting, they're trying to make a consistent rule to have everyone format it a certain way. This time it might not matter (even though expanding it in THIS case very easily shows the issue with the code) but if they don't correct the person now, they might come back with more complicated code next time and not format it correctly and no one will be able/willing to help him.
It serves multiple purposes:
1) To possibly help the person posting the code by being able to look at it formatted correctly (though if it's being posted here, it's unlikely that's going to be the case) 2) To make it easier for the people providing help to read it 3) To show a basic level of consideration/consistency when posting. If the person is unwilling to follow directions THAT specifically outlined (and reinforced by multiple posters here), it's unlikely that any help provided will be able to help the person a) solve their problem or b) become a better programmer.
The posters here are trying to help people find the problems and UNDERSTAND what they're solving, not to simply hand them a solution without them UNDERSTANDING what the problem is.
So yeah, you can argue all you want about it, you could even be right about it but at the end of the day, if the people providing you help ask for something, you can question or fight them about it (and end up in the huge tangent displayed here) or you can just follow their suggestion and move on and I'm sure they'll be happy to help you with your code at that point.
But realistically, if you try to help someone and they fight you over it, how likely are you to continue helping someone?
No. I was replying to your rather sloppy description of what matters to a compiler.
View all questions in Keil forum