How to define "

Is there anyway to define " ?

Example:

1
2
3
4
5
6
7
8
#define apos "

#define CONCAT(a,b,c) a ## b ## c
#define INDIR_CONCAT(a,b,c) CONCAT(a,b,c)

#define CONDITION INDIR_CONCAT(apos,This is a test,apos);

printf(CONDITION);


The thing that i'm trying to do is to make a define for " and use that define instead of using ".

printf(aposThis is a testapos);

apos means "
I already tried this, but it isn't working.
Last edited on
This is a bad idea for several reasons, and I don't think it would work even if you could define something as "

 
#define CONDITION INDIR_CONCAT(apos,This is a test,apos) 


Here, even if apos is defined as " (which is a quotation mark, not an apostrpohe, just fyi), CONDITION would expand to this:

INDIR_CONCAT(",This is a test,")
which would give you a different error since you're now only passing one parameter to INDIR_CONCAT instead of the required 3.


But the bigger issue here is that this is a wretched abuse of macros.
Last edited on
Mm, lets change the code like this:

1
2
3
#define text "This is a test"

printf(text);


I want to make the define called TEXT like this:

1
2
3
4
5
#define quo "

#define text quoThis is a testquo

printf(text);
Last edited on
Can you explain why you are trying to do this?
Just curiosity. I'm working on the different define methods.
Even if this is allowed (which I'm not sure it is), you have the same problem.

quoThis is a different token from quo, so that wouldn't expand at all.

And quo ## This ## quo might expand to " ## This ## ", or even " ## This ## quo not "This"

What you're trying to do is just incredibly fugly and riddled with a million potential problems. Don't do it.
Last edited on
The C++ preprocessor works on C++ tokens. An unclosed quote character is not a valid token.
It may work if you run the preprocessor as a stand-alone program (rather than letting the compiler call it for you)
Thanks for the answers. I'll be waiting to see is there anyone who can make it.
1
2
3
4
5
6
7
8
9
10
#define q(t) #t

#define CONDITION q(This is a test)

#include <cstdio>

int main()
{
	std::printf(CONDITION);
}
I know this way but the thing that i want isn't like this. Thanks anyway :), i'm going to mark the topic as solved. The last may help people who search for an answer.
Last edited on
Topic archived. No new replies allowed.