News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

problem with quotation marks in #defines in project options

Started by mkaut, March 27, 2009, 12:28:59 PM

Previous topic - Next topic

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?
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?
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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

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?
That's because the compiler says so. We can't do anything about that.

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?
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.
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".

#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;
}


The "Build options -> Compiler settings -> #defines"-tab contains:TEST="The String"

The output (started from inside C::B) is:
The String

Process returned 0 (0x0)   execution time : 0.000 s
Press ENTER to continue.


It works on windows and linux without scripting or any quotation-incompatibilities .