From 92f94e4e5b271142caaaa8dabf0d21c1a8db1ae2 Mon Sep 17 00:00:00 2001 From: acqn Date: Thu, 1 Sep 2022 12:58:52 +0800 Subject: [PATCH] A space character will be inserted in front of a leading '#' pp-token as the result of macro expansion. --- src/cc65/preproc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cc65/preproc.c b/src/cc65/preproc.c index 87d6a7878..833dea9d4 100644 --- a/src/cc65/preproc.c +++ b/src/cc65/preproc.c @@ -2216,6 +2216,13 @@ static unsigned ReplaceMacros (StrBuf* Source, StrBuf* Target, MacroExp* E, unsi InitLine (TmpTarget); PushRescanLine (CurRescanStack, TmpTarget, LastTokLen); + /* Add a space before a '#' at the beginning of the line */ + if (CurC == '#' && + NextC != '#' && + (SB_IsEmpty (Target) || SB_LookAtLast (Target) == '\n')) { + SB_AppendChar (Target, ' '); + } + /* Switch the buffers */ TmpTarget = NewStrBuf (); } else if (PendingNewLines > 0 && MultiLine) {