Am 31.03.24, 17:45 schrieb 837806295 via Tinycc-devel <tinycc-devel@nongnu.org>:

Hi 837806295.

Using a name for communication is better...


> Hello!
> Report a Bug about Parsing #ifdef, #ifndef and #else Line.

Your intention to write a bug rebort is good,
but your example is not vaild C code.

From your example:

> {
> #ifndef Test #else
> printf("Hello, Test\n");
>
> #endif



* A preproceccing directive starts with a hashtag and ends with a newline.

Correct in your example

* The #ifdef preprocessor directive starts an ` if-section`
and is followed by an identifier and a newline


Since an `identifier` is not allowed to contain any whitespace,
the requirements of the C standard not met by your example,
so your example is not valid c code,
and every c compiler is allowed to do anything with your text file


tcc expects that the source code is correct,
and has only simple error checking.
Since "Test #else" (insert more space/tab here)
is not defined, the example is compiled and "Hello, Test\n" is printed.


gcc expects that the source code is correct,
but tries sometimes a workaround on developer mistakes.
For your example, gcc decides, that the identifier stops after the "Test"
and gives you a warning:
warning: extra tokens at the end of #ifndef directive
The example is compiled, but "Hello, Test\n" is not printed.


openwatcom expects that the source code is correct,
and bails out with an error on your example:
Error! E1009: Expecting 'end of line' but found '#'
Since an Error was detected, the compilation in aborted.

All three Compiler are correct.


For reference: Section 6.10 in the C standard: Preprocessing directives
C99: n1256.pdf
C11: n1570
C17: n2176
C23: n3096.pdf

In my c89 draft, Preprocessing directives are in section 3.8


> Fix:
> According to your decision.

This is not a bug in tcc.


--
Regards ... Detlef
_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to