473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Why would anyone do this?

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?

Thanks in advance for any advice.

James
Nov 14 '05 #1
4 1256
bl*********@hotmail.com (Blue Ocean) writes:
#define FDECL(functionname,params) functionname(params)

And then declarations like this (from include/extern.h, nethack):

E int NDECL(dojump);


Presumably this is a dodge for old compilers that don't support
prototypes.
--
"The fact that there is a holy war doesn't mean that one of the sides
doesn't suck - usually both do..."
--Alexander Viro
Nov 14 '05 #2
Blue Ocean wrote:
#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);
Hmmm, half of these are NDECL, not FDECL!
Why? Is there any compelling reason not to type out the prototype?
This doesn't even save characters. Am I missing something?


Nethack is probably one of the most widely ported programs. As such, it had
to deal with various compilers, most of which are - by current standards -
broken and/or obsolete. Take a look at all the files of Nethack, I'm sure
you will find a definition for a compiler that does not resolve to a
prototype that you would have written.

I can't properly parse what you wrote, but it somehow reminds me of the old
way to write a function. It was
int foo( param)
float param
{ return 667; }

instead of
int foo( float param)
{ return 42; }

In short: Nethack is not the right source for learning C.

Uli

Nov 14 '05 #3
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
Nov 14 '05 #4
In <2k************@uni-berlin.de> Ulrich Eckhardt <do******@knuut.de> writes:
I can't properly parse what you wrote, but it somehow reminds me of the old
way to write a function. It was
int foo( param)
float param
{ return 667; }


Not really: each parameter declaration was terminated with a semicolon
and these declarations were typically aligned with the first line of the
function definition and the opening brace:

int main(argc, argv)
int argc; /* optional: undeclared parameters were int by default */
char **argv;
{
/* get the work done */
}

Note that even C99 supports this function definition syntax, but each
parameter must be explicitly declared (another instance of no implicit
int in C99).

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: asdf sdf | last post by:
i have an install issue with moinmoin on win2k. i've tried the mailing list, but it appears to be a very low traffic, low subscriber list. can i get a reality check? is anyone using moinmoin in...
1
by: Simon Harvey | last post by:
Hi chaps, Does anyone know if the beast is going to release Visual Tools for office to work with Visual Studio 2002 and not just 2003, or are they quite happy to shaft those that supported them...
1
by: Greg Steele | last post by:
Does anyone have a copy or know where I can get an installation executable for chiliReports 2.0 from chili! soft? The company I'm working for bought a copy several years ago, then moved their...
2
by: Ken Shaw | last post by:
G'day, I'm trying to tack down any delta compression library that I could licence for use in a project. Does anyone know of a decent binary delta compression library? cheers, Ken Shaw
0
by: james | last post by:
Hi guys! I´ve got a centerd table on my site with a black 1 pixel border. What i would like to do is to add a drop shadow to the table. Anyone know if it's possible to create a drop shadow for a...
162
by: Isaac Grover | last post by:
Hi everyone, Just out of curiosity I recently pointed one of my hand-typed pages at the W3 Validator, and my hand-typed code was just ripped to shreds. Then I pointed some major sites...
0
by: Jay1969 | last post by:
Hey all, I heard there was a new service offered to Microsoft partners called ISV Advisory Services (see link) where MS is giving free dev consulting to their Partners. ...
13
by: penguin732901 | last post by:
Checking back for discussions, there was a lot of talk about 2000 being slower than 97, but not so much lately. What is the latest opinion? Anyone care to set up a poll for how many NG members...
2
by: Brent Taylor via AccessMonster.com | last post by:
HELP----DOES ANYONE HAVE A SIMPLE .mdb for MLM structure? Does anyone have an example database for multi-level marketing for a 3 Tier setup? Thank you, brenttaylor@actionimports.net
2
by: Bruno Alexandre | last post by:
Hi guys, does anyone know where is the Website used in the MSDN "Lear ASP.NET 2.0 with Jeff Prosise" (http://msdn.microsoft.com/asp.net/beta2/multimedia/default.aspx) events? The website used...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.