Remove String Quotations Using The Preprocessor

Mar 27, 2013 at 1:42pm
Hi,

I'm trying to use a #define function directive to remove string quotations. Kind of like the opposite of stringizing.

For example, if there was an operator to do this which I am representing as ~ (I know there isn't but if there was). I want it to be like:

1
2
#define macr(name) ~name
text macr("name") othertext

This would then turn it into:

text name othertext

Note I am not doing this to try and get a variable value, I am running a parser upon the outputted code afterwards. I know I could use the parser itself to remove the string quotations but I want to know if there is any possible way of doing this using the preprocessor?

Thanks for any help.
Last edited on Mar 27, 2013 at 1:59pm
Mar 27, 2013 at 2:52pm
Remove all qutation:
#define "
Mar 27, 2013 at 4:20pm
I don't wish to remove all the quotations, just those put in the macro function.
Last edited on Mar 27, 2013 at 4:20pm
Mar 27, 2013 at 4:59pm
If you only wanted to add it...
...
...
Try this:
1
2
3
4
5
#define macro("
#define ")orcam

//usage
macro("name")orcam

Why won't you just write name without quotes?
Mar 28, 2013 at 3:13pm
Why won't you just write name without quotes?

I don't have any control over the input format.

^ That's a great idea though. But I don't know how you define braces? If you try #define macro(" it errors that it wants a closing brace as macros use the braces for the function notation.
Last edited on Mar 28, 2013 at 3:13pm
Mar 28, 2013 at 3:28pm
I don't have any control over the input format.

You do know that preprocessor works before compilation and before any input can be made, right?

Give me an example, how do you want ot use this macro.
Mar 28, 2013 at 3:34pm
If the input is from a file, consider piping it through something that can do the replacement for you like sed, perl, etc..
Mar 28, 2013 at 3:40pm
Doesn't seem like a good idea to me, but I don't have much of an idea. I would say do it in the parser to keep the original file in it's original state.
Mar 28, 2013 at 3:50pm
You do understand that you should force those who send you an input file to use your macro, and if you can do that you can just tell them to not use quotes.
Topic archived. No new replies allowed.