Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 17th, 2006, 10:22 PM   #1
DBZ
Newbie
 
Join Date: Feb 2006
Posts: 22
Rep Power: 0 DBZ is on a distinguished road
Help with this. Can you check what's missing?

on this line
#define DO_INIT_STRUCT(ddstruct)
{
memset (&ddstruct, 0 , sizeof(ddstruct));
ddstruct.dwSize = sizeof(ddstruct);
}

What is missing up there? Cuz I kept getting an error
error C2447: missing function header (old-style formal list?)

Thxs
DBZ is offline   Reply With Quote
Old Mar 17th, 2006, 10:57 PM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
You really need to read the "How to post a question" sticky thread at the top of the C++ forum. That gives useful advice on how to ask questions to increase your chances of getting a useful answer.

That said, you got lucky..... this time. The answer to your question is that macros only work on one line by default. If you want a macro to work across multiple lines, you need to use a "continuation marker" so the preprocessor knows that what you intend. The "continuation marker" is a backslash on the end of ALL except the last line of the macro.
#define DO_INIT_STRUCT(ddstruct)      \
{      \
memset (&ddstruct, 0 , sizeof(ddstruct));   \
ddstruct.dwSize = sizeof(ddstruct);    \
}
Note that there is no continuation marker on the last line.

If you want to be safer, you will actually do something like this;
#define DO_INIT_STRUCT(ddstruct)      \
do {      \
memset (&ddstruct, 0 , sizeof(ddstruct));   \
ddstruct.dwSize = sizeof(ddstruct);    \
} while(0)
One reason for the do {}while (0) surround is that, without them, the code;
if (some_condition)
   DO_INIT_STRUCT(some_struct);
else
   do_something_else();
will always generate a compiler error. With the do {} while (0) surround it will work as is usually intended.
grumpy is offline   Reply With Quote
Old Mar 17th, 2006, 11:39 PM   #3
DBZ
Newbie
 
Join Date: Feb 2006
Posts: 22
Rep Power: 0 DBZ is on a distinguished road
sorry grumpy i didnt know how this forum systemw works and i did not intentionally do it on purpose. forgive me. but thxs for helping me out. Your a nice guy. Anyways, I will go and take a look through the rules of how to post....
DBZ is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:22 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC