0

I'm trying to get a bunch of C modules written in 1994 for a Panasonic 3DO lib to compile with armcc. I've run into an error which I'm kind of confused about. My knowledge of C is not that deep, so perhaps one of you would be so kind as to help me figure this out:

#define DS_MSG_HEADER   \
    long        whatToDo;   /* opcode determining msg contents */               \
    Item        msgItem;    /* message item for sending this buffer */          \
    void*       privatePtr; /* ptr to sender's private data */                  \
    void*       link        /* user defined -- for linking msg into lists */

The \ character is used in many include files in this library I'm unfamiliar with this syntax... and the ARM compiler seems to hate it.

Serious error: misplaced preprocessor character '\'

If you know why these \ characters are being used, could please explain? (Sorry if its a noob question) Also, is there an alternative way to write this so the compiler is happy?

Shpack
  • 11
  • 1
  • Try using macros that the compiler does not flag as errors. – TomServo Jul 26 '21 at 01:43
  • 3
    The code shown, by itself, should be perfectly fine. A stab in the dark: run all the `.c` and `.h` files through `dos2unix`. If that fixes it, I will explain. If not, we're going to need you to construct what we call an [MCVE](https://stackoverflow.com/help/mcve/) -- a minimal but _complete_ example program that we can compile ourselves and get the same errors you're getting. – zwol Jul 26 '21 at 01:45
  • 12
    Make sure there aren’t any blanks after the backslash character - it needs to be the last character on the line. – John Bode Jul 26 '21 at 01:46
  • Be warned that a program written in 1994 to run on a video game console is very likely to be objectionable to modern C compilers for several other reasons. – zwol Jul 26 '21 at 01:49
  • 3
    @JohnBode Thanks for the tip. I changed from Macintosh style line endings to Unix style and the error is gone :) – Shpack Jul 26 '21 at 02:26

1 Answers1

4

This error is shown (among other reasons) if the shown backslash '\' is not the last character on the line.

I can think of two reasons:

  1. Somehow you got at least one whitespace (space, tab) after the backslash.

    I never had this problem.

  2. The source is stored with Windows-style end-of-line markers, that are '\r' and '\n', "carriage return" and "line feed". And you are trying to compile it on a Unix-like system (Linux?) or by a compiler that expects Unix-like end-of-line markers, that is only '\n', "line feed". (Or the other way around.)

    This is a quite common problem, that hits me time after time.

In any case, open the source in a capable editor and enable the visibility of "unvisible characters", commonly an option with this icon: . Check for whitespace. Then check for the coding of the end-of-line. Save with the appropriate one.

the busybee
  • 10,755
  • 3
  • 13
  • 30