Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Old C compiler chokes on #ifndef #define

I am trying to port some relatively modern C code to an older compiler.

This compiler (DICE), it seems, chokes on the first header file and the first occurrence of this idiom:

#ifndef SOMETHING
#define SOMETHING

...  

#endif /* SOMETHING */

it dies on the second line in the header with: DCPP: "../../code/someheader.h" L:2 C:0 Error:39 Syntax Error

Changing to #define SOMETHING 1 made no difference.

So I have really two questions, am I using DICE with the wrong option or something, or did C programmers use some other idiom equal to ifndef-define back in the old days?

References:

  • DICE Wikipedia Entry
  • Original source code, runs on Unix
  • Slightly updated Amiga version
  • The author of DICE, Matt Dillon, went on to produce DragonFlyBSD
like image 969
Prof. Falken Avatar asked Nov 17 '11 15:11

Prof. Falken


2 Answers

If it is this C compiler then by looking at the sources (src\dcpp\cpp.c) you can see that newlines only include the carriage return character and not the linefeed character.

If you have a line ending with CRLF then when the compiler strips the whitespace at the start of the line, it does not strip the linefeed before the # which is a syntax error, since preprocessor directives starting with # must be the first non-whitespace character in the line.

like image 52
tinman Avatar answered Nov 14 '22 18:11

tinman


#if SOMETHING
#else




#endif

might just work everywhere

like image 38
parapura rajkumar Avatar answered Nov 14 '22 17:11

parapura rajkumar