I posted a similar question yesterday, the site suggested to post a new question with better explanations.
There are two macros:
#define COMPANY L"Test Company"
#define PRODUCT COMPANY L" in Canada"
The result of PRODUCT will be "Test Company in Canada".
Now, we have the following requirements:
- make the COMPANY to be "dynamic" string, to call a function to return a company name, e.g . #define COMPANY getCompanyName()
- we are not allowed to change the other code to reference the COMPANY, such as #define PRODUCT COMPANY L" in Canada", since there are so many macros in the code
The issue with change: The result of PRODUCT will be "Test Company", lost the part " in Canada" literal.
Here is the code:
#include <stdio.h>
#include <tchar.h>
const wchar_t* getCompanyName() { return L"Test Company";};
#define COMPANY getCompanyName();
#define PRODUCT COMPANY L" in Canada"
int _tmain(int argc, _TCHAR* argv[])
{
const wchar_t * company = COMPANY; // get Test Company
const wchar_t * product = PRODUCT; // get Test Company in Canada
wprintf(company);
wprintf(product);
return 0;
}