Misdirected bug?

The following line was in my sketch:

#define EEPROMENCODERASLEEP      0
#defene EEPROMENCODERREVIEW      2
#define EEPROMENCODERWRITE       4

// ...a bunch of code

   eepromEncoderStatus = EEPROMENCODERREVIEW ;

The compiler flags the last code line above as an error. So, I checked to make sure I didn't misspell eepromEncoderStatus , which I didn't. I then checked to see if I had misspelled EEPROMENCODERREVIEW, which I hadn't. After scratching my head a few times, I realized I had misspelled "define" as "defene". Yes, I realize it's better to use const with such definitions, and this is a good reason why. I guess it's one of those old-dog-new-tricks issues. Anyway, the compiler seems to do a little misdirection on this type of error.

Anyway, the compiler seems to do a little misdirection on this type of error.

It’s not the compiler. The preprocessor ran, saw #defene, had no rules to govern what to do with that directive, so it discarded the name and value.

The preprocessor ran, saw #defene, had no rules to govern what to do with that directive, so it discarded the name and value.

but not before telling you with an error message

error: invalid preprocessing directive #defene

This is as good an argument in favour of keyword highlighting as any I’ve seen.

PaulS: Back in the 1980's my company produced an MSDOS C compiler and we treated all of the preprocessor directives as keywords, which would have places the error message on the directive rather than its use later on. That's why I said "misdirected" in the tag line.

all of the preprocessor directives as keywords

That's not how it's done in classic K+R C. The # keywords are dealt with by the preprocessor which is a program in its own right and can be used on its own if you want a macro processor. The # stuff does not form part of the syntax of the language and is gone before the compiler sees it.

The mis-placed error message is a problem with all languages which allow a macro processor.

Mark