User forums > Help
problem with quotation marks in #defines in project options
(1/1)
mkaut:
Hello,
there seems to be a difference between Linux and Windows version in handling quotation marks (") in defines in project properties: in Windows, the quotation marks must be escaped as \", while the Linux version needs \\".
Is this only my problem, a feature, or a bug?
And if it is a feature, is there some way how to make the project file work on both platforms, other than duplicating the targets?
I have tested this on 8.02 on WinXP and 8.02 and the latest nightly on Linux (Xubuntu).
Thanks,
Michal
MortenMacFly:
--- Quote from: mkaut on March 27, 2009, 12:28:59 pm ---Is this only my problem, a feature, or a bug?
--- End quote ---
That's because the compiler says so. We can't do anything about that.
--- Quote from: mkaut on March 27, 2009, 12:28:59 pm ---how to make the project file work on both platforms, other than duplicating the targets?
--- End quote ---
You can use scripting for that purpose. Using scripting you can (depending on the platform which you can query via script, too) set the define as required.
mkaut:
--- Quote from: MortenMacFly on March 27, 2009, 01:59:21 pm ---
--- Quote from: mkaut on March 27, 2009, 12:28:59 pm ---Is this only my problem, a feature, or a bug?
--- End quote ---
That's because the compiler says so. We can't do anything about that.
--- End quote ---
I do not understand. On both platforms (Windows and Linux), gcc on the commandline needs -DDEF_NAME=\"DEF_VALUE\", i.e. using single backslash to escape the quotation mark.
The difference is that if I specify this in #defines in the 'Project build options', I have to use DEF_NAME=\"DEF_VALUE\" on Windows and DEF_NAME=\\"DEF_VALUE\\" on Linux. In other words, it seems to me that the difference comes from C::B, not from the compiler...
--- Quote from: MortenMacFly on March 27, 2009, 01:59:21 pm ---
--- Quote from: mkaut on March 27, 2009, 12:28:59 pm ---how to make the project file work on both platforms, other than duplicating the targets?
--- End quote ---
You can use scripting for that purpose. Using scripting you can (depending on the platform which you can query via script, too) set the define as required.
--- End quote ---
Thanks, I did not know that .. never used scripting in C::B before.
Would you know about some place where I can learn about it? I have not found much useful in the C::B manual..
Jenna:
If I understand right, you want to pass a parameter via define on commandline and use it as string inside the program.
Is this correct ?
google leads me to this post: http://bytes.com/groups/cpp/443326-portable-way-pass-string-c-macro
This is a sample code that outputs a string passed to gcc with -DTEST="The String".
--- Code: ---#define ToString1_(x) #x
#define ToString_(x) ToString1_(x)
#define MyDefinedString ToString_(TEST)
#include <iostream>
using namespace std;
int main()
{
cout << MyDefinedString << endl;
return 0;
}
--- End code ---
The "Build options -> Compiler settings -> #defines"-tab contains:
--- Code: ---TEST="The String"
--- End code ---
The output (started from inside C::B) is:
--- Code: ---The String
Process returned 0 (0x0) execution time : 0.000 s
Press ENTER to continue.
--- End code ---
It works on windows and linux without scripting or any quotation-incompatibilities .
Navigation
[0] Message Index
Go to full version