syntax error near 'int': why?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Alright, this is going to make me look really stupid, but I have searched for this error message and got zero results. I like to add an obvious indication to my code so that I know that the code loaded and at least this simple function is working, if not the others. For the following code:

   

#include <project.h>

   

int main()
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    uint8 LED_On = 0;

   

        /* Place your initialization/startup code here (e.g. MyInst_Start()) */

   

    for(;;)
    {
        /* Place your application code here. */
        LED_Write(LED_On);
        CyDelay(500);
        LED_On = !LED_On;

   

    }
}

   

I get the following errors:

   

Build error: syntax error near 'uint8' (I assume that "uint8" is a valid type)

   

Build error: 'LED_On': undefined identifier (one per line that LED_On appears in).

   

I can't figure out how something so basic is a problem except that I need to include another library and I find nothing that tells me what to include. What resource tells me how to write C for Creator? 

0 Likes
1 Solution
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

Hi Jeffery,

   

 

   

move the variable definition of 'LED_On' at the first position in main() function (above interrupt enable) and try again.

   

If I remember correctly the Keil compiler doesn't allow definitions/declarations 'in the middle of the code'.

   

 

   

Regards,

   

 

   

Ralf

View solution in original post

8 Replies