Search code examples
ccompiler-errorsembeddedsyntax-errorinterrupt-handling

Embedded C code unexplainable syntax error; Expected ... before '{' token


I started to use Eclipse right now and I noticed that there is this one error occuring, at every function that I write. Nothing helps with that yet.

#include "init.h"
#include "irq.h"

void T0Handler (void) _attribute_ ((interrupt ("IRQ")));


int main(void)
{
    systemInit(); /*CCLK = 50MHz; PCLK = 25MHz*/

    install_irq(TIMER0_INT, T0Handler, 0);

    for(;;);
}

Above is just an initializing code snippet.

However, an error pops up saying:

Description Resource Path Location Type expected '=', ',', ';', 'asm' or 'attribute' before '{' token assignment1.c Template_Proteus line 14 C/C++ Problem

it cannot be true in terms of main func. as it expects those tokens written in-between main() and the main's opening curly bracket.

Such problems are occuring at every function I write in Eclipse (working in Virtualbox).

Also, in the T0Handler declaration, there is constant syntax issue with the

_attribute_ ((interrupt ("IRQ"))) part.


Solution

  • Eclipses' parser (which is what is driving the in-editor highlights) does not understand the compiler-specific extension that you are using.

    Not sure how to work around this, but it's a common enough problem in embedded development I think.

    I found an answer adapted from here that states that you can fix it by writing code targeting Eclipse's indexer like so:

    #ifdef __CDT_PARSER__
    #define _attribute_ (...)
    #endif
    

    I have not tested this.