Author Topic: problem with quotation marks in #defines in project options  (Read 4724 times)

Offline mkaut

  • Multiple posting newcomer
  • *
  • Posts: 10
problem with quotation marks in #defines in project options
« on: March 27, 2009, 12:28:59 pm »
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

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: problem with quotation marks in #defines in project options
« Reply #1 on: March 27, 2009, 01:59:21 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.

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: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline mkaut

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: problem with quotation marks in #defines in project options
« Reply #2 on: March 27, 2009, 02:57:54 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...

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

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: problem with quotation marks in #defines in project options
« Reply #3 on: March 27, 2009, 10:20:03 pm »
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;
}

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

The output (started from inside C::B) is:
Code
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 .