Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ Programming
➜ STL
➜ Macro Definition Explained
Macro Definition Explained
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Goldbishop
(6 posts) Bio
|
Date
| Mon 10 May 2010 02:15 AM (UTC) |
Message
| While looking over the structure of the DikuMUD codebase i am looking at, i found this Macro definition that in itself doesnt make any sense, to me at least.
If it would be possible to get someone to explain to me what the purpose of defining this macro is and what it is doing.
...
#define PROFILE(x)
...
PROFILE(extern etext();)
...
PROFILE(monstartup((int) 2, etext);)
...
I understand what the X value being passed to the PROFILE macro is, as well as how macro's work, but this one is throwing me for a loop as the Macro isnt explicitely defining the inline code to replace but instead its like it is just dumping it into the void of code.
Any explanation would be greatly appreciated. And no there is no space between PROFILE and (x), they are all one "word", per say. | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #1 on Mon 10 May 2010 02:18 AM (UTC) |
Message
| I assume that the PROFILE macro itself is defined in two places, one when enabled and one when disabled. The one you posted is likely the disabled one, meaning everything passed in is completely ignored. There's probably another that actually does stuff, but which definition is used is controlled by a compile-time option. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Goldbishop
(6 posts) Bio
|
Date
| Reply #2 on Mon 10 May 2010 02:26 AM (UTC) |
Message
| in the current *.c file i am looking at it is only defined once and used, as far as i can tell, in one subroutine. Outside of that there is no #undef.
i am still looking at this one file, so there might be but i havent seen another yet.
Funny part is that it occurs rather early in the file but not at the top, it is defined after the main() function of the file but before the next function.
for example:
<header info>
..
int main(....)
{
....
}
#define PROFILE(x)
int run_the_game(...)
{
....
PROFILE(....)
...
PROFILE(....)
...
PROFILE(...)
}
thats the only 4 spots in the whole file that this macro occurs.
I am wondering if it had a use at one point and then was badly commented out. They just removed the Macro functionality to basically end any calls into a NULL reference. | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #3 on Mon 10 May 2010 02:28 AM (UTC) |
Message
| Hmm, I don't know. Maybe it was defined in a header and they wanted to (badly) disable it in that part of the file. But I can tell you that, from what you've posted, that's a no-op macro. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Goldbishop
(6 posts) Bio
|
Date
| Reply #4 on Mon 10 May 2010 02:32 AM (UTC) |
Message
| ok, i am no ansi-C programmer but i can understand it for the most part....keep a gnu.org link to the bsd/gnu c framework handy on my desktop.
this one was throwing me for a loop and i marked as a "come-back to at a later time".
thanx again twisol | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #5 on Mon 10 May 2010 03:14 AM (UTC) |
Message
| Probably it is a poor mans debugging of sorts. When a developer is working on it, he includes a header which defines the profile different, counting a start and end time, and probably printing it to output somehow. This will allow him to see how long that part of the code has taken. The process of finding out how much time the different parts of ones code takes is called profiling.
Real profiling does not do it on a call basis but tracks the more complete image without need of macros and as a part of a debugging suite. Hence me calling it a poor mans form of profiling. :) | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #6 on Mon 10 May 2010 01:52 PM (UTC) |
Message
|
Quote: Real profiling does not do it on a call basis
Yes it does... perhaps you meant that you don't typically specify the functions you want profiled one-by-one?
(By the way, this isn't an STL-related question at all. The STL is a C++ standard library.) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
25,312 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top