Why does the following C/C++ macro not work? -


it seems simple, can't figure out. here question: have simple function returns string:

const wchar_t* getcompanyname() { return l"test company";}; 

i want define macro following:

#define company getcompanyname(); #define product company l" in canada"  const wchar_t * company = company;  const wchar_t * product = product;  

i expect see "product" value "test company in canada", shows "test company" , string "in canada" never concat product string

thank time, here full 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; // test company     const wchar_t * place = product; // test company in canada      wprintf(company);     wprintf(place);      return 0; } 

because of

#define company getcompanyname(); 

remove semicolon:

#define company getcompanyname() 

to elaborate, way have written:

const wchar_t * product = product; 

expands into:

const wchar_t * product = getcompanyname(); l" in canada"; 

the

l" in canada"; 

is fine expression on own nothing. morale of story: careful semicolons in macros, not necessary, may be.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -