Question on macros

Hi,

I came across this piece of code which used macro in a way I have never seen/couldn't understand. I tried googling but couldn't find anything like this. Source is from openVXI - open source implementation of voicexml.

extern "C" const VXIchar* VXIinterpreterGetImplementationName(void)
{
#ifndef COMPANY_DOMAIN
#define COMPANY_DOMAIN L"com.yourcompany"
#endif
static const VXIchar IMPLEMENTATION_NAME[] = COMPANY_DOMAIN L".VXI"; // how does this work?

return IMPLEMENTATION_NAME;
}

How does this work out? Any explantions?

Thanks.
if the macro COMPANY_COMAIN has not been defined with a specific value before this code in the current source file (and it's includes), it will be defined here with a default value
You are also seeing the automatic string literal concatenation that C and C++ do. For example:

1
2
3
4
5
6
7
8
9
#include <iostream>

int main()
  {
  std::cout <<
    "Hello "
    "world!\n";
  return 0;
  }
Sorry. I should have been more clear about the question.

Is L in (#define COMPANY_DOMAIN L"com.yourcompany) a part of macro name (i.e. COMPANY_DOMAIN) or it's definition? I am confused by the use of space in between 'COMPANY_DOMAIN' and 'L'.

If VXIchar is defined as

typedef wchar_t VXIchar;

what is the expected value of IMPLEMENTATION_NAME here?



I see this 'L' being used many places in the code .e.g

inline bool Compare(const XMLCh * x, const VXIchar * y)
{
}

is invoked in code like

if (Compare(attributeValue, L"2.0")) version = 2.0f;

where attributeValue is of type const XMLCh* and 2nd param is supposed to be of type const VXIchar*. What am I missing or not knowing here? Is 'L' something special in C++?

Thanks.
closed account (DSLq5Di1)
The L prefix denotes a wide string literal,
1
2
char    str1[] = { "This is a string literal" }; // 1 byte per character
wchar_t str2[] = { L"This is a wide string literal" }; // 2 bytes per character 
Ahh! Thanks. That helps a lot.
Topic archived. No new replies allowed.