Skip to content

"register" is not highlighted as a keyword, and the compiler gives a cryptic error #1154

Closed
@adzenith

Description

@adzenith

"register" is a keyword in C++, so using it as a variable name doesn't work. However, Arduino doesn't give much indication that this is the case: it doesn't highlight the word, and the compiler message is opaque.

Example code:
void foo(int register) {
Serial.write(register);
}

Error:
sketch_dec06b.ino: In function 'void foo(int)':
sketch_dec06b:2: error: expected primary-expression before 'register'

Note that the error doesn't come until the Serial.write line, because the compiler views the "int register" as a nameless argument of type "int register", rather than an attempt at making an int variable named "register". This makes debugging very confusing.

I think an easy fix would be to highlight the word "register"; ultimately, it would be nice if the compiler could spit out a nicer error in this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions