In <33**************************@posting.google.com >
bl*********@hotmail.com (Blue Ocean) writes:
Hey all, I'm a newbie and just learning C. I've been teaching it to
myself since I got home from school for the summer. I've also been
reading some code and I've been seeing a lot of this:
#define FDECL(functionname,params) functionname(params)
And then declarations like this (from include/extern.h, nethack):
E int NDECL(dojump);
E int FDECL(jump, (int));
E int NDECL(number_leashed);
E void FDECL(o_unleash, (struct obj *));
E void FDECL(m_unleash, (struct monst *,BOOLEAN_P));
E void NDECL(unleash_all);
E boolean NDECL(next_to_u);
etc.
Why? Is there any compelling reason not to type out the prototype?
This doesn't even save characters. Am I missing something?
Yup, you're missing the fact that you're looking at an *old* application.
You're also missing the fact that, under certain circumstances, FDECL
may be defined like this:
#define FDECL(functionname,params) functionname()
The point is not to save typing, but to provide prototype function
declarations to compilers that understand them, while still keeping
pre-ANSI compilers happy. Some people believed that the above technique
is a great idea, others went for the more readable:
#ifndef __STDC__
int jump();
void o_unleash();
void m_unleash();
#else
int jump(int);
void o_unleash(struct obj *);
void m_unleash(struct monst *, BOOLEAN_P);
#endif
What is lost by the marginally higher maintenance overhead (each
function has to be declared twice) is more than won back by the
improved readability: the code actually looks like C code.
Using macros that mess with the C syntax is seldom a good idea.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email:
Da*****@ifh.de