[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  Programming
. -> [Folder]  STL
. . -> [Subject]  Macro Definition Explained
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Macro Definition Explained

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Goldbishop   (6 posts)  [Biography] bio
Date Mon 10 May 2010 02:15 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by Twisol   USA  (2,230 posts)  [Biography] bio
Date Reply #1 on Mon 10 May 2010 02:18 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Goldbishop   (6 posts)  [Biography] bio
Date Reply #2 on Mon 10 May 2010 02:26 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by Twisol   USA  (2,230 posts)  [Biography] bio
Date Reply #3 on Mon 10 May 2010 02:28 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Goldbishop   (6 posts)  [Biography] bio
Date Reply #4 on Mon 10 May 2010 02:32 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Worstje   Netherlands  (867 posts)  [Biography] bio
Date Reply #5 on Mon 10 May 2010 03:14 AM (UTC)  quote  ]
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. :)
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Reply #6 on Mon 10 May 2010 01:52 PM (UTC)  quote  ]
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
[Go to top] 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.


3,767 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]