Preprocessor C: removing quotes from an argument

I am abusing the C preprocessor for my build system to create a readme text file and a web page from the same source file. The design looks something like this:

Actual definitions are in data.h:

#define WEBSITE "http://example.com"

Please note that //the URL must be specified, otherwise it will be considered as the beginning of the comment. A similar problem occurs when used ,in an argument; quotes are needed, otherwise the comma will be considered as a separator of arguments.

Using this header, the file is readme.txt.pplaunched through the C preprocessor :

#include "data.h"
Visit the website at WEBSITE!

Of course, the output of the preprocessor:

Visit the website at "http://example.com"!

. , :

Visit the website at http://example.com!

Visual ++ 2008. , ; , V++, . ( XML XSLT, XML , -.)

+3
3

XSLT, document() .

, WEBSITE, . m4 C.

+2

, , , , - , , ...

:

#define DUMMY  
#define WEBSITE http:/DUMMY/example.com  

, , DUMMY .

+2

Try disabling C ++ style comments if possible. I don’t know how this works in VS, but using the GCC compiler I can pass a flag -std=c89to gcc to disable C ++ style comments and therefore do

#define WEBSITE http://example.com

perhaps.

0
source

Source: https://habr.com/ru/post/1727202/


All Articles