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.
Not very nice but you really think it's hard to read? It's virtually a one liner. and so what.
There are CLEAR instructions as to how to post code above the "Enter Message Details Below" box and FOLLOWING INSTRUCTIONS would make the difference between (in this case somewhat) hard to read and easy to read.
Erik
See the picture: www.danlhenry.com/.../keil_code.png
Yes - it's virtuala a one liner.
And a one liner that suffers specifically from not keeping track of scope of for - something that happens when the code isn't properly indented.
So what is your view on that? You think it helps to see the scoping error when it's all on a single line, Trevor?
So what is your view on that?
Since you asked, I'll tell you what my view is.
I would hazzard a guess that the OP is fairly new at programming, but most beginners at C tend to format their code a bit better than what is in the post. Therefore, it is far more likely that he simply did the cut/paste operation without adding the tags.
So, your comments are really only appropriate to what is shown here and not what might be shown on the OPs computer screen.
Congratulations. You found the error. Maybe you edited the code yourself to see it more clearly, maybe you didn't. But, for a simple one liner like that, someone familar with C would (and should) be able to scan the line quite easily. Of course, I'm not talking about the huge cut/paste of code that sometimes occurs on posts on this forum, but a simple one liner really is pretty simple.
It also tires me to see the self proclaimed style police kick off about the small things and miss the big things. Just recently we had a consultant come in and do a code review on a colleagues project. Plenty of 'this is terrible' and 'this is wrong'. Most were concerned with comments and naming conventions. He even made a really big thing about how in one place in the code it mentioned that the tab setting was 8, when it was actually 6 and then added it should be 4. But he managed to miss a fundamental error in the code itself. It was big, it was obvious, it was serious, it was the type of thing he was contracted to check for and it was missed by him. To me, that was simply shameful. Suffice it to say, we have not asked for his services again and his tweets show he feels aggrieved. Tough.
Sorry, but your comment reminded me of what that consultant wrote.
I'm sure you and your cohorts will have a view on what I have said, but remember that you did ask!
Yes, I'm fairly good at reading oneliners.
But the important thing here is that the OP have issues with C scoping rules - what forms a complete for() loop.
And such a debate would be many times easier if the OP had posted the code in a way where the code had corresponded with his views on scoping rules.
Not having read the posting instructions, makes it impossible to know what the OP thought formed a for loop. But it seems logical to assume that the OP thought a for() alone on same line would be enough - missing that the compiler will continue to following lines looking for a statement or block.
The important thing is that this type of questions should have contained not just a part of an error message, but the compilete error message. That error message would then indicate a line number too. And if the OP had done what a smart poster would have done - marked which line the error message mentioned - it would have been even easier to have the OP see why the message said what it said.
I really don't care what indentation styles other people selects, as long as they follow "my" indentation style when doing changes to "my" code. But for a beginner, it is totally important to be strict with a code layout where it is 100% visible what binds to what - and where blocks and statements ends.
Another interesting thing that happens when people ignore the proper posting instructions, is that source code instructions happens after end of one-line comments, since a web browser have no idea that the original line breaks was important. So it can be impossible to know what source lines was commented away by the poster, and what source lines just looks commented away in the posting.
In the end, posters often save 30 seconds by not checking the posting instructions. Then they waste minutes for the people who could possibly help. Then they end up having wasted hours or days because they don't get the help that was available.
Not checking posting instructions to save time is just ass efficient as premature optimization of code - it normally ends up costing a lot.
I would hazzard a guess that the OP is fairly new at programmingM also new at following instructions?
someone familar with C would (and should) be able so, when helping others using your free time you shall just do more work than is needed because the one asking can't follow directions? Even something as small as what triggered this takes quite a bit longer to figure out when not formatted
It also tires me to see the self proclaimed style police kick off about the small things and miss the big things. What does "following directions" (use pre ...) have to do with 'style'?. Are you saying that "I can't read your code" is not a valid reason to "miss the big things". How can you catch the big things if you can't read the code?
In the end, posters often save 30 seconds by .... Then they waste minutes for the many people who could possibly help.
minutes * many versus to seconds * one
Even something as small as what triggered this takes quite a bit longer to figure out when not formatted
With all due respect, the time it takes is going to depend upon the skill set and experience of the person viewing the code. For example, i seem to have picked up a reputation for quickly seeing spelling mistakes and typos in text that others frequently miss. Yes Erik, your posts frequently show up on my radar!
Are you saying that "I can't read your code" is not a valid reason to "miss the big things".
Not at all. I was trying to say that being fixated with the small things at the expense of the big things is a particularly dumb thing.
"I was trying to say that being fixated with the small things at the expense of the big things is a particularly dumb thing."
Not when the little thing is a ';'.
But what is your view on the first for() loop in the posted code? Did the OP intend it as a empty for loop for a delay? Or a loop that should perform multiple writes of 0xFF to the port? Is there a way we can know, without seeing the code complete with the original indentation? Does it make a big difference in the result, when running the code?
By the way - compare posting time of my first answer with the creation time of this thread. And remove time for writing the text. I obviously can't have spent too much time on that mess, to pinpoint the issues. But does that make it less of a mess, because of the lack of indentation?
Pers reply quoted above DOES inform the OP what the problem is (I guess that qualifies as the "big thing")
and you react to the comment about missed formatting (I guess that qualifies as the "small thing")
now you post I was trying to say that being fixated with the small things at the expense of the big things is a particularly dumb thing I think the pot is calling the kettle black
That might even have been a valid argument, were it not for the fact that what is shown here was shown on the OP's screen first. That's exactly what the preview-before-post mechanism was created for.
So the OP did see that the formatting was shot, and decided to post it as broken as it was.
Lesson learned: before you blame others, try to get your facts straight.
The "pre" "/pre" is not so much (at least in this case) about whether it's readable or not, but it's about making sure the original poster is putting in at least the most basic effort. A lot of times if the poster can't even be bothered to format correctly, responders take it as "if he doesn't care enough to make it easier on us, we're not going to bother helping him." At the end of the day, it's up to the responders as they are providing the help. It takes almost no time to add those in and, to be fair, adding those tags in is documented right above the post and, while it can be easy to look past, it should be easy to correct.
In this case, more important than the "pre" thing is proper indentation. Indentation takes code that looks like this:
void main ( ) { int x; while (1) { P1 = 0x00 ; for (x=0 ; x<=5000 ; x++) P1 = 0xFF ; for (x=0 ; x<=5000 ; x++) } }
to code that looks like this:
Once it's expanded like this, it's actually not too hard to see what the issue is (hint: you often get that error when you have code that is not properly terminated, mostly from semicolons. This time, it's not due to a semicolon but it's pretty easy to spot). This should get you started.
In the future, try to indent your code a bit better as it will help you solve these kind of problems much easier in the future and will get you a much quicker response when you DO need to post code.
Good luck!
IF the OP really can't spot something as clearly & obviously stated as the posting instructions, that tends to suggest a lack of attention that is really going to hamper their progress with any sort of programming - and embedded programming in particular.
You may call it a "little thing", but it is precisely such sloppiness with the "little things" - in this case, just one "little" semicolon - that is the cause of the problem reported in the OP's post!
When it comes to compilers (and circuits, for that matter) the "little things" really do matter - the compiler will not cut you any slack because you're a beginner and it's "only" one "little" semicolon...
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?
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.
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?
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
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?
"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.
Sounds like most of this comes as a result of the confusion between me and the morgan guy but for all intent and purposes, let me explain where I get this from, so you understand I wasn't making anything up . . .
While this is true, I saw it as you jumped in only when people were already heading down that direction. It seemed like you came out of nowhere to just jump on people over the way they post and were never interested in helping out with the original code.
That's probably a bit unfair of an analysis on my part but that was my reaction to it. Sorry about that.
Maybe ass was the wrong word but the point of the statement is that I was being made to look like the jerk for defending my statements about nitpicking (which, as you mentioned was a result of my posts looking like Morgan's), more by Erik than yourself.
This statement right here implied inexperience (though I guess in context to the forums themselves, I looked too far into this regarding my own embedded experience). So that was a misunderstanding on my part, I wasn't trying to make anything up.
So, long story short, a series of misunderstandings and it all headed off on some complete unnecessary tangent that distracts from the original posts. Though, to be fair, in all the time this has taken, the OP still hasn't bothered to come in here and follow up with any updates so I guess it's all a moot point. Unless the Nirav person is the same as the Morgan guy . . .
Heh, doesn't matter at this point. It looks like its an escalating series of misunderstandings.
View all questions in Keil forum