473,804 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(functionn ame,params) functionname(pa rams)

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

E int NDECL(dojump);
E int FDECL(jump, (int));
E int NDECL(number_le ashed);
E void FDECL(o_unleash , (struct obj *));
E void FDECL(m_unleash , (struct monst *,BOOLEAN_P));
E void NDECL(unleash_a ll);
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 1273
bl*********@hot mail.com (Blue Ocean) writes:
#define FDECL(functionn ame,params) functionname(pa rams)

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(functionn ame,params) functionname(pa rams)

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

E int NDECL(dojump);
E int FDECL(jump, (int));
E int NDECL(number_le ashed);
E void FDECL(o_unleash , (struct obj *));
E void FDECL(m_unleash , (struct monst *,BOOLEAN_P));
E void NDECL(unleash_a ll);
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*********@hot mail.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(functionn ame,params) functionname(pa rams)

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

E int NDECL(dojump);
E int FDECL(jump, (int));
E int NDECL(number_le ashed);
E void FDECL(o_unleash , (struct obj *));
E void FDECL(m_unleash , (struct monst *,BOOLEAN_P));
E void NDECL(unleash_a ll);
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(functionn ame,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(struc t obj *);
void m_unleash(struc t 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
1318
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 win2k? any issues? anyone at all?
1
2100
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 when their product just cam out. I can't see why the tools shouldnt work with 2002 seeing as its almost identical to 2003. Has anyone heard anything
1
1489
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 datacenter and lost the installation in the process. I have the registration e-mail that was sent to them with the unlocking code so we just need the trial installation executable.
2
3693
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
2277
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 table? Does anyone has an example? Thanks, James
162
7299
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 (microsoft.com, cnn.com, etc.) at the W3 Validator; to my surprise none of them passed. Doesn't anyone care anymore, or are the standards more-or-less looked at as guidlines for web design?
0
1079
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. https://partner.microsoft.com/global/40016379 Has anyone in these groups had a chance to try them out? It sounds like it may be a good service but I'd like to hear from anyone who's
13
2231
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 are still using 97? 2000? I am slightly tempted to upgrade by a new client whose data is in 2000, but of course, I can just port it all back through Excel...right? and I guess I have seen a couple of nice features...
2
3910
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
2325
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 is called "Contoso", but I can't find it in the MSDN site, so I can evaluate it with the webcasts. If anyone know here is it, or if anyone is using it, please post here a
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10600
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10354
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10097
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9175
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.