This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

c++.c(17): error C141: syntax error near '}' THIS ERROR SHOWN PLZ HELP ME

#include<AT89X51.h>
void delay(unsigned int);
void main(void)

{ P1_1=0; /* unset pin # 1*/

P1_2=0; /* unset pin # 2*/

/* bring delay*/

delay(300); P1_1=1; /* set pin # 1*/ P1_2=1; /* set pin # 2*/ /*bring delay*/ delay(300)
}

/* define delay function*/
void delay(unsigned int itime)
{ int i,j; for (i=0;i<itime;i++); for (j=0;j<5000;j++);
}

Parents
  • Why do you have a file named c++ but with an extension ".c"? You want to make readers confused about if the code is written in C or in C++?

    Next thing - you get an error. The error specifies a line number. Why don't you think it's important for the readers of your post to know where that line number is in your code?

    Another thing - you think your comments are helping you understand the code? Or why do you write "unset pin #1" after P1_1=0?

    And why do you mix if having the comment after the instruction (I have to assume it's at the end of the line) or directly before the line? What reasoning did you make to figure out that comments for delays should be before the function call while comments about pin toggling should be after the code?

    Why do you do "nested for loops" in the delay function, without actually nesting the loops? And have you lots of posts on the net recommending for-loops as a great way to implement delays? What does actual "300" means? 300 microseconds? 300 milliseconds? 300 sighs? Wouldn't it be better for a reader if your delays make use of some physical unit that a reader can comprehend? Your busy-loop aren't even making use of the volatile keyword - why should the compiler keep the iterations instead of just throwing them away since there are no side effect?

    Yet another thing - what do you think happens when your program exists the main() function? You think it will return to the Windows desktop? Or will a command-line prompt magically appear? This is a forum for embedded development, and you claim you are using a tool chain for 8051 processors - look for sample code and you'll notice that the code really shouldn't exit main().

    #include<AT89X51.h>
    
    void delay(unsigned int);
    void main(void)
    
    {
        P1_1=0; /* unset pin # 1*/
        P1_2=0; /* unset pin # 2*/
    
        /* bring delay*/
        delay(300);
    
        P1_1=1; /* set pin # 1*/
        P1_2=1; /* set pin # 2*/
    
        /*bring delay*/
        delay(300)              <=== don't you also fail to see a ';'?
    }
    
    /* define delay function*/
    void delay(unsigned int itime) {
        int i,j;
    
        for (i=0;i<itime;i++);  <=== are you sure this was how you intended the
        for (j=0;j<5000;j++);   <=== delay to function?
    }
    

Reply
  • Why do you have a file named c++ but with an extension ".c"? You want to make readers confused about if the code is written in C or in C++?

    Next thing - you get an error. The error specifies a line number. Why don't you think it's important for the readers of your post to know where that line number is in your code?

    Another thing - you think your comments are helping you understand the code? Or why do you write "unset pin #1" after P1_1=0?

    And why do you mix if having the comment after the instruction (I have to assume it's at the end of the line) or directly before the line? What reasoning did you make to figure out that comments for delays should be before the function call while comments about pin toggling should be after the code?

    Why do you do "nested for loops" in the delay function, without actually nesting the loops? And have you lots of posts on the net recommending for-loops as a great way to implement delays? What does actual "300" means? 300 microseconds? 300 milliseconds? 300 sighs? Wouldn't it be better for a reader if your delays make use of some physical unit that a reader can comprehend? Your busy-loop aren't even making use of the volatile keyword - why should the compiler keep the iterations instead of just throwing them away since there are no side effect?

    Yet another thing - what do you think happens when your program exists the main() function? You think it will return to the Windows desktop? Or will a command-line prompt magically appear? This is a forum for embedded development, and you claim you are using a tool chain for 8051 processors - look for sample code and you'll notice that the code really shouldn't exit main().

    #include<AT89X51.h>
    
    void delay(unsigned int);
    void main(void)
    
    {
        P1_1=0; /* unset pin # 1*/
        P1_2=0; /* unset pin # 2*/
    
        /* bring delay*/
        delay(300);
    
        P1_1=1; /* set pin # 1*/
        P1_2=1; /* set pin # 2*/
    
        /*bring delay*/
        delay(300)              <=== don't you also fail to see a ';'?
    }
    
    /* define delay function*/
    void delay(unsigned int itime) {
        int i,j;
    
        for (i=0;i<itime;i++);  <=== are you sure this was how you intended the
        for (j=0;j<5000;j++);   <=== delay to function?
    }
    

Children