Why does #define INVALID_VALUE -999; give a syntax error when used?

后端 未结 6 2105
长发绾君心
长发绾君心 2020-12-11 22:40

I am trying to compare to a defined constants in C, and I have simplified my program to the following:

#include \"stdio.h\"
#include \"stdlib.h\"
#define INV         


        
6条回答
  •  粉色の甜心
    2020-12-11 23:31

    The C Preprocessor Macro Language is Distinct from C


    The ; in the macro definition should be removed.

    This is an understandable mistake. If C were designed today, the macro language might be more integrated with the rest of C.

    But on 16-bit machines in the early 1970's when C was invented, it was unwise to write an overly complicated program. It would end up useless as there would be no memory remaining to actually run the big masterpiece program, and even simple programs ran slowly.

    So C was split into a rather simple macro preprocessor that was, originally, a completely separate program, and the compiler proper. The preprocessor program made no attempt to parse C beyond understanding the lexical analysis model.

    When 32-bit machines took over, the preprocessor was typically integrated into the parser, but naturally the language needed to remain the same.

提交回复
热议问题