tinycpp icon indicating copy to clipboard operation
tinycpp copied to clipboard

Don't print newline on trailing #endif

Open prez opened this issue 5 years ago • 4 comments

tinycpp <<EOF
#if x
#endif
EOF

Prints a newline. Should it? During my examination of the code, I wasn't able to find a non-intrusive change that does not require peeking forward, which it seems you intentionally avoid.

prez avatar Feb 12 '20 02:02 prez

hmm, for some reason i wasn't "watching" my own repo, so i wasn't notified of your report. i don't know the answer off the top of my head but the README specifically mentions that tinycpp preserves whitespace, however it's questionable whether it should in this case. does this break something, or is it a theoretical question?

rofl0r avatar Oct 09 '20 20:10 rofl0r

Another example where it becomes clearer that an extra newline is printed would be:

tcpp <<EOF
#if x
a
#endif
b
EOF

This prints "\nb\n", where the first newline is superfluous. To answer your question, it for sure does not break the intended use case (being a C preprocessor).

For context, I was investigating lightweight alternatives to m5, and tinycpp could in my opinion be a good general-purpose preprocessor.

prez avatar Oct 10 '20 09:10 prez

m5? are you refering to https://compilers.iecc.com/comparch/article/92-10-076 which i couldn't find any more information about, or did you mean to say m4?

rofl0r avatar Oct 10 '20 22:10 rofl0r

Yes, I meant to say m4. Interesting find!

prez avatar Oct 11 '20 08:10 prez