Re: [Tinycc-devel] bug in preprocessor

2024-01-19 Thread Fred van Kempen via Tinycc-devel
> To put some text after #endif on the same line, this used to be customary> in 
> K age, wasn't it?Yes, and that has evolved into using comment markers 
> there, likein #endif    /*foo*/
for example.
> There are K sources still valuable today and it is really useful that 
> Tinycc is capable of compiling them.Yes, but it should generate a warning, 
> like it does with old-style function argument declarations, and leavingout 
> base types of variables... both were legel in K, too :P
Fred
  ___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] bug in preprocessor

2024-01-19 Thread Fred van Kempen via Tinycc-devel
> It also compiles, with a warning, both with GCC (13.2.0) and Clang 
> (15.0.7).It should generate a warning, yes.
Fred
  ___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] bug in preprocessor

2024-01-19 Thread Harald Arnesen via Tinycc-devel

Fred van Kempen via Tinycc-devel [18/01/2024 21.35]:


This:

#include 
#include 

int
main(int argc, char **argv)
{
#ifdef FOO
     printf("Foo: %s\n", argv[0]);
#endif  bar

     return argc;
}

should not compile, for obvious reasons, but it does..

Using 0.28rc.


It also compiles, with a warning, both with GCC (13.2.0) and Clang (15.0.7).
--
Hilsen Harald



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


Re: [Tinycc-devel] bug report / preprocessor / string literals

2006-02-13 Thread Bernhard Fischer
On Fri, Jan 27, 2006 at 12:16:20PM +0100, [EMAIL PROTECTED] wrote:
Hi @,

There seems to be a bug in the preprocessor when using # to create string
literals.

The following source ...

#define printxml(xml) printf(#xml)
#define nl printf(\n)

int main() {
printxml(
html
/html
);
nl;
return 0;
}

... compiled with tcc yields the following output:

 html   / html 

The same source compiled with cc yields the following (correct) output:

html /html

This may be easy to fix, but I'd need a hint where to look in the source,
not time to go searching...

To me it looks like these args should not be tokenized but each read in
one slurp (until eol or end of arg -- '\'' or ')').

Didn't look into this yet, but perhaps look at parse_define() and
next_nomacro1(). I'm not certain if adding a TOKEN_FLAG for string
literals is ok (as said, i didn't look into it):

@@ -320,7 +320,8 @@ static CString tokcstr; /* current parse
 static int tok_flags;
 #define TOK_FLAG_BOL   0x0001 /* beginning of line before */
 #define TOK_FLAG_BOF   0x0002 /* beginning of file before */
-#define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting
#ifdef */
+#define TOK_FLAG_ENDIF 0x0004 /* an endif was found matching starting
#ifdef */
+#define TOK_FLAG_STR   0x0008 /* is a string literal */
 
 static int *macro_ptr, *macro_ptr_allocated;
 static int *unget_saved_macro_ptr;


and then flagging them
@@ -3577,7 +3580,7 @@ static inline void next_nomacro1(void)
 if ((tok_flags  TOK_FLAG_BOL)  
 (parse_flags  PARSE_FLAG_PREPROCESS)) {
 file-buf_ptr = p;
-preprocess(tok_flags  TOK_FLAG_BOF);
+preprocess(tok_flags  (TOK_FLAG_BOF | TOK_FLAG_STR));
 p = file-buf_ptr;
 goto redo_no_start;
 } else {
@@ -3951,7 +3954,7 @@ static int *macro_arg_subst(Sym **nested
 st = (int *)s-c;
 notfirst = 0;
 while (*st) {
-if (notfirst)
+if (notfirst  (parse_flags 
PARSE_FLAG_PREPROCESS))
 cstr_ccat(cstr, ' ');
 TOK_GET(t, st, cval);
 cstr_cat(cstr, get_tok_str(t, cval));

HTH,
Bernhard


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/tinycc-devel