-3

I wanted to compile a project yesterday which always worked until now. Probably since an adjustment of the libraries (update) I have not been able to do this anymore. I ask for help.

ERRORMESSAGE: exit status 1 expected ':' before '{' token

Line from Error

#define MSG_PRINT(...) { MSG_PRINTER.print(__VA_ARGS__); }
3
  • With all those compile errors in here, we should consider renaming from Arduino to Does-Not-Compile. - Have you even tried to google how to define function-like macros and how to use them? – Kwasmich Jun 16 '20 at 8:49
  • what is the value of MSG_PRINT(...) after the #define directive is evaluated? – jsotola Jun 16 '20 at 8:51
  • What comes in your code just before you use MSG_PRINT? – Majenko Jun 16 '20 at 9:12
2

MSG_PRINT is a macro. It gets replaced in your code verbatim before compilation.

The error message will give you more information. Specifically it will tell you where the error is. For example:

/tmp/untitled1/untitled1.ino: In function 'void loop()':
/tmp/untitled1/untitled1.ino:1:24: error: expected ':' before '{' token
/tmp/untitled1/untitled1.ino:12:13: note: in expansion of macro 'MSG_PRINT'

Here I have defined MSG_PRINT at line 1, which is where it "says" the error is. However that's only where the macro is. The actual error is at line 12, where the error says the macro is being expanded. That's the last line in the error message.

The little bit of code I used to trigger that error is actually a switch command where I deliberately omitted the : at the end of a case statement:

    switch (v) {
        case 3 // <---- missing colon here
            MSG_PRINT("foo");
            break;
    }

If we replace MSG_PRINT as the preprocessor would we end up with:

    switch (v) {
        case 3
            { Serial.println("foo"); }
            break;
    }

(I defined MSG_PRINT to just call Serial.println...) and now we can better see the context of the error.

With the expansion now in place it is obvious that there is indeed a : missing before a {, even though that { isn't immediately visible in your code.

Learning to interpret these sometimes cryptic error messages is key to working with C and C++.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.