|
|
Someone asked me this question this morning - and I didn't have an answer. Can anyone explain why it is bad to use a macro function?
Dylan
|
|
|
|
|
because there is no controle on the parameters passed to it. second reason, we are obliged not to separate the macro name and the opening parenthesis '(' that follow it, which is not very practical.
TOXCCT >>> GEII power
|
|
|
|
|
toxcct wrote:
we are obliged not to separate the macro name and the opening parenthesis
Only in the macro's definition, not its usage.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
ok sorry, it was confused in my mind... but, that was a bit right anyway
thx for the precision...
TOXCCT >>> GEII power
|
|
|
|
|
|
There is no type checking.
Ant.
|
|
|
|
|
thank you
very useful !
TOXCCT >>> GEII power
|
|
|
|
|
Here is the classic example:
#define tolower(x) (isupper(x)?(x)-32: (x))
*pOut++ = tolower(*pIn++);
What does that expand to?
*pOut++ = (isupper(*pIn++)?(*pIn++)-32: (*pIn++));
Due to the expansion, pIn will be incremented twice. This is a behavior that is totally different from what is expected when tolower is defined as a function.
Here is another example
#define DOADD5(x) x+5
int iOutput = DOADD32(1)*2;
What is the result, 12? Nope, the result is 11.
When you look at the expansion, you get 1+5*2. Do to operator precedence, you get 5*2 then add 1 instead of 1+5 then times 2.
Some of these problems can be avoided, some can not.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
|
Whether it is always bad is a matter of opinion.
Bad things about macros:
1) No direct validation of arguments.
2) Micro expansion could lead to unexpected results.
Examples:
#define MUL(a,b) (a*b) // bad macro
MUL(123-45,678-90) expands to (123-45*678-90) equals -30477
#define MUL2(a,b) ((a)*(b)) // better macro
MUL(123-45,678-90) expands to ((123-45)*(678-90)) equals 45864
Good things about function inlining:
1) Arguments are validated at compile time.
2) There is no expansion of arguments; therefore no misunderstanding of what the result will be.
Example:
inline int Mul(int a, int b) { return a * b; }
Mul(123-45,678-90) equals 45864
INTP
|
|
|
|
|
I use Windows ApiHook hooked the ExtTextOut and Successfully replace theorginal function with MyExtTextOut.
i want replace orginal Text with myText.but after replaced ,there only display some text. for exam :
orginal text="My Computer",(11 char)
after replace by myText="My and Your Computer"(20 char) there only display "My and Your" (11 Char).
How can i display full text.
thank you!
uqtur@163.com
uqtur
|
|
|
|
|
Where can i copy codes from to use in my database?
|
|
|
|
|
the program below ,when i set point(0,0) ,i can see those strings in view ,but when i set point(20,-20) ,those strins only can be seen in File/Print Preview.
void CTestView::OnDraw(CDC* pDC)
{CTestDoc* pDoc = GetDocument();
CString str;
//CPoint point(0,0);
//pDC->TextOut(point.x,point.y,"tanghuitian");
//point+=CSize(20,-20);
str.Format("%6.6s%6.6s%6.6s%6.6s%6.6s","index","left","top","right","bottom");
pDC->TextOut(point.x,point.y,str);
}
|
|
|
|
|
Its the way a window display works. The top left corner is 0,0. So when plotting on your screen display it falls outside the clipping region in use and is not shown. During print preview, no clipping region is in force, and point 0,0 is still in the top left of the page, but at the start of the printable area of the page (i.e. indented by the margin amounts).
Your string at (20, -20) is off the top on screen
but visible in print preview due to the extra canvas and lack of clipping region
Roger Allen - Sonork 100.10016
Strong Sad:
Clever I am? Next to no one.
Undiscovered and soggy.
Look up. Look down. They're around.
Probably laughing. Still, bright, watery.
Listed among the top. Ten.
Nine. Late night. Early morn.
Early mourn. Now I sleep.
|
|
|
|
|
Can somebody post me a link where a UNICODE file is loaded and it's content is displayed on a Dialog? So how to load a UNICODE file ? How to display a UNICODE text on a Dialog?
Thanks
xxx
|
|
|
|
|
I'm sure there was a class on CP that can load Unicode text, try to search. Underneath, the is no easy way to do it - you simply load portion-by-portion, analyzing content. Unicode file can start with signature (FFFE or FEFF) - this will help to to understand what you have. But it is not required - in this case you will have to try to detect if text is unicode (see ::IsTextUnicode()). As for displaying, it depends on your project - if it is Unicode-enabled, then no problems. Otherwise you will need to convert to plain text.
Igor Green
http://www.grigsoft.com/ - files and folders comparison tools
|
|
|
|
|
Here it is:
http://www.codeproject.com/file/stdiofileex.asp
Igor Green
http://www.grigsoft.com/ - files and folders comparison tools
|
|
|
|
|
Well thanks,
but I also have a problem with displaying the text (_UNICODE is defined on my project). I can display the UNICODE text only with AfxMessageBox , when I try to set a STATIC TEXT control value to that text it does not show it correclty . Also wprintf(...) is not working .
xxx
|
|
|
|
|
have a look at this^[^]
I Dream of Absolute Zero
|
|
|
|
|
I want to create a modeless Property Sheet Wizard, with the Context Help icon in the System Menu (top right corner) ?
Is there a way to get it work ?
|
|
|
|
|
Why do i get in Windows 98 GetClipboardSequenceNumber undeclared identifier?
RegisterShellFilesType(TRUE) for a dialog box based on CRichEditCtrl gives me a debug
assertion failed: appui2.cpp line 191. I find ASSERT(m_pDocManager != NULL); and
m_pDocManager is CDocManager variable type which is a derived class from Object, but what is
CDocManager and what do i have to do in order not to appear this assert?I get this message after i close my app.
How ca I implement MRU list in a dialog box?I know about CRecentFileList, but how can i do it because i need a menu item?
Where I can have the mfc faq?
And please don't tell me about CRichEditView , I already know about it but I can't re-write my entire app because it is quite complex.
I have the following code for Find/Replace , but it doesn't working and not even the selection is not working as it should be.
bool CMyRtfDlg::FindWhatYouNeed( bool bMatchCase, bool bMatchWholeWord, bool bSearchDown)
{
FINDTEXTEX findText;
findText.lpstrText = (LPTSTR) (LPCTSTR) findName;
findText.chrg.cpMin = 0;
findText.chrg.cpMax = -1;
int nLen=findName.GetLength();
long lResult = m_rtf.FindText(0, &findText);
CString s;
s.Format("%d",lResult);
SetWindowText(s);
if (lResult == -1)
{
MessageBox("No matches!");
bSearchDown = false;
return false;
}
else
{
m_rtf.SetSel(lResult,nLen);
bSearchDown=true;
//findText.chrg.cpMin = lResult + 1;
//long lResult = m_rtf.FindText(0, &findText);
}
return true;
}
Thanks a lot.
|
|
|
|
|
Filomela wrote:
Why do i get in Windows 98 GetClipboardSequenceNumber undeclared identifier?
I assume you have the right .h files included. Do you have WINVER defined? If not, take a look at line #4389 of wsinuser.h.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I need a MIS.The personnel asministrative system of company,if you have the source code ,can you give to me as an example,thank you .
my mail box is:xuxu83@hotmail.com
|
|
|
|
|
This makes no sense. What does Management of Information Services have to do with source code?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|