|
I use it in some crude way of code generation:
I can automagically declare an Interface and define a smart-ptr type to it by just writing INTERFACE(Name)
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Hi jhwurmbach,
I have tried to use ##, but the code does not compile.
<br />
#define PREFIX(x) _T("FOO")##x<br />
<br />
int main()<br />
{<br />
<br />
const TCHAR* SecondArray [2] = {_T("FILE1"), _T("FILE2")};<br />
<br />
TCHAR* p = NULL;<br />
p = PREFIX(SecondArray [0]);<br />
p = PREFIX(SecondArray [1]);<br />
<br />
<br />
return 0;<br />
}<br />
Error information,
main.c(11) : error C2146: syntax error : missing ';' before identifier 'SecondArray'
main.c(12) : error C2146: syntax error : missing ';' before identifier 'SecondArray'
regards,
George
|
|
|
|
|
George_George wrote: #define PREFIX(x) _T("FOO")##x
p = PREFIX(SecondArray [0]);
Sure. This would make the compiler see
p = _T("FOO")SecondArray [0];<br />
p = _T("FOO")SecondArray [1];<br />
Not exactly what you want.
Remember, we are doing text-replacement here. The C++compiler is not running. Not the slightest trace of C++ at this level!
What we are trying to use here is called the Token-Pasting Operator as I just looked up
You want to write something like
#define PREFIX( x ) _T("FOO##x")<br />
const TCHAR* SecondArray [2] = { PREFIX(FILE1), PREFIX(FILE2)};
-- modified at 8:52 Thursday 22nd November, 2007
Corrected the issue toxcct found
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
jhwurmbach wrote: Sure. This would make the compiler see
p = FOOSecondArray [0];
p = FOOSecondArray [1];
no, the compiler sees :
p = _T("FOO")SecondArray [0];
p = _T("FOO")SecondArray [1];
jhwurmbach wrote: You want to write something like
#define PREFIX( x ) _T("FOO##x")
not either. this will be transformated into
p = _T("FOOSecondArray [0]");
|
|
|
|
|
Part 1
Yes, you are right. I am glad I do not work as a Text-Preprocessor...
Part 2
Not when I write
PREFIX(FILE1)
That would indeed become
_T("FOOFILE1")
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
you're probably right, but infortunately, i have no compiler with me at the moment.
|
|
|
|
|
Hi jhwurmbach,
I think your code does not compile. Are there anything wrong?\
<br />
#define PREFIX(x) _T("FOO##x");<br />
<br />
<br />
int main()<br />
{<br />
<br />
const TCHAR* SecondArray [2] = {PREFIX(_T("FILE1")), PREFIX(_T("FILE2"))};<br />
<br />
TCHAR* p = NULL;<br />
p = SecondArray [0];<br />
p = SecondArray [1];<br />
<br />
<br />
return 0;<br />
}<br />
main.cpp(9) : error C2143: syntax error : missing '}' before ';'
main.cpp(9) : error C2143: syntax error : missing ';' before ','
main.cpp(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(12) : error C2040: 'p' : 'int' differs in levels of indirection from 'TCHAR *'
main.cpp(12) : error C2065: 'SecondArray' : undeclared identifier
main.cpp(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(13) : error C2040: 'p' : 'int' differs in levels of indirection from 'TCHAR *'
main.cpp(16) : error C2059: syntax error : 'return'
main.cpp(17) : error C2059: syntax error : '}'
main.cpp(17) : error C2143: syntax error : missing ';' before '}'
main.cpp(17) : error C2059: syntax error : '}'
regards,
George
|
|
|
|
|
As toxcct said quite rude, you do not bother to read up the hints we give you.
The way you defined the macro, the line looks to the compiler like
const TCHAR* SecondArray [2] = {_T("FOO_T("FILE1")");, _T("FOO_T("FILE2")");};
And you wonder why it does not compile?
Remember: ##x in the macro-definition is replaced with whatever is written in the braces after PREFIX
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Sorry jhwurmbach, it is my mistake to add an additional ; sign.
Now the code works. You are so cool.
regards,
George
|
|
|
|
|
George_George wrote: Now the code works.
It still produces garbage, as long as you don't do something about the _T
Maybe you understand now why we were not too keen to suggest macros.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Hi jhwurmbach,
I have tested that the code works as expected, adding FOO to prefix too all constant string. What do you mean produces garbage?
It is appreciated if you could show some code.
regards,
George
|
|
|
|
|
Hi toxcct,
Your code does not compile. Have I correctly applied your ideas?
<br />
#define PREFIX(x) _T("FOO")##x<br />
<br />
int main()<br />
{<br />
<br />
const TCHAR* SecondArray [2] = {_T("FILE1"), _T("FILE2")};<br />
<br />
TCHAR* p = NULL;<br />
p = PREFIX(SecondArray [0]);<br />
p = PREFIX(SecondArray [1]);<br />
<br />
<br />
return 0;<br />
}<br />
Compile error,
main.c(11) : error C2146: syntax error : missing ';' before identifier 'SecondArray'
main.c(12) : error C2146: syntax error : missing ';' before identifier 'SecondArray'
regards,
George
|
|
|
|
|
hey you !
not only you don't copy my code correctly, but you modify it wrngly and you vote my post without even knowing what you're talking about
go to hell with you macro. if you can't play with your compiler to test so things, and read the C++ doc, then don't expect me to answer you anyfurther.
|
|
|
|
|
Hi toxcct,
Actually your code does not compile, could you try please? I have tried twice. If there is any mistake I have made in the code, please feel free to let me know.
<br />
#define PREFIX(x) _T("FOO##x");<br />
<br />
<br />
int main()<br />
{<br />
<br />
const TCHAR* SecondArray [2] = {PREFIX(_T("FILE1")), PREFIX(_T("FILE2"))};<br />
<br />
TCHAR* p = NULL;<br />
p = SecondArray [0];<br />
p = SecondArray [1];<br />
<br />
<br />
return 0;<br />
}<br />
main.cpp(9) : error C2143: syntax error : missing '}' before ';'
main.cpp(9) : error C2143: syntax error : missing ';' before ','
main.cpp(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(12) : error C2040: 'p' : 'int' differs in levels of indirection from 'TCHAR *'
main.cpp(12) : error C2065: 'SecondArray' : undeclared identifier
main.cpp(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(13) : error C2040: 'p' : 'int' differs in levels of indirection from 'TCHAR *'
main.cpp(16) : error C2059: syntax error : 'return'
main.cpp(17) : error C2059: syntax error : '}'
main.cpp(17) : error C2143: syntax error : missing ';' before '}'
main.cpp(17) : error C2059: syntax error : '}'
regards,
George
|
|
|
|
|
George_George wrote: Actually your code does not compile, could you try please
you're an idiot, you cannot even copy paste correctly.
have you seen a ; after my macro definition ?
certainly not. that's certainly it though.
|
|
|
|
|
Be patient, mon ami
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
all he deserves is let down on is crap
he doesn't even understand all we explain to him, but still he thinks he has the right to vote anyhow.
|
|
|
|
|
toxcct wrote: he doesn't even understand all we explain to him, but still he thinks he has the right to vote anyhow
I know, this is very unpleasant
BTW using the token-pasting operator with string is tricky, I had to fight a bit before finding the way out [^].
It was only for academical interest however: I keep thinking the search-replace tool of his IDE was more valuable there.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Sorry, it is my carelessness. I have removed the ; sign and it works! Cool!
have a good weekend,
George
|
|
|
|
|
I want to change windows size of SDI project(CFromView).
what's function can support this issue
|
|
|
|
|
Do you tried already MoveWindow?
|
|
|
|
|
Hello,
Have you checked SetWindowPos() method of CWnd.That might help to change the size of the window .
Pritha
|
|
|
|
|
|
Hello,
Make your question clear Hamid?
Prithaa
|
|
|
|
|