[comp.lang.c] ANSI-compatible function declarations with args

yost@tss.com (Dave Yost) (03/27/91)

See this:

#ifdef __ANSI__ && !defined (PROTO)
#define PROTO
#endif

#undef decl_args
#ifdef PROTO
#define decl_args(x) x
#else
#define decl_args(x) ()
#endif

Are there any standards for what to call this 'decl_args' macro?

 --dave yost

yost@tss.com (Dave Yost) (03/28/91)

See this:

#ifdef __ANSI__ && !defined (PROTO)
#define PROTO
#endif

#undef decl_args
#ifdef PROTO
#define decl_args(x) x
#else
#define decl_args(x) ()
#endif

Are there any standards (preferably only one)
for what to call this 'decl_args' macro?

As perhaps all of you know, a macro like this
allows one to write function declarations
which work optimally with both ANSI and non-ANSI
compilers.  Example:

extern void qsort decl_args ((
    char* base,
    int nelements,
    int width,
    int *(compar) decl_args ((char* e1, char* e2))
));

 --dave yost

meissner@osf.org (Michael Meissner) (03/28/91)

In article <1991Mar27.011212.5929@tss.com> yost@tss.com (Dave Yost) writes:

| See this:
| 
| #ifdef __ANSI__ && !defined (PROTO)
| #define PROTO
| #endif

You probably mean something like:

#ifndef PROTO
#ifdef __STDC__
#define PROTO
#endif
#endif

since your #ifdef line is illegal, and the define that ANSI specifies
is __STDC__.

| #undef decl_args
| #ifdef PROTO
| #define decl_args(x) x
| #else
| #define decl_args(x) ()
| #endif
| 
| Are there any standards for what to call this 'decl_args' macro?

I tend to call it PROTO myself.
--
Michael Meissner	email: meissner@osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Considering the flames and intolerance, shouldn't USENET be spelled ABUSENET?

rex@aussie.COM (Rex Jaeschke) (03/28/91)

Dave Yost asks:

> #ifdef PROTO
> #define decl_args(x) x
> #else
> #define decl_args(x) ()
> #endif
> 
> Are there any standards for what to call this 'decl_args' macro?

If you are an implementer I have seen only __ used as the name. As a user, 
I use xx. It's short and not too distracting allowing you to still read the 
function declaration around it.

Rex

----------------------------------------------------------------------------
Rex Jaeschke     |  Journal of C Language Translation  | C Users Journal
(703) 860-0091   |        2051 Swans Neck Way          | DEC PROFESSIONAL
rex@aussie.COM   |     Reston, Virginia 22091, USA     | Programmers Journal
----------------------------------------------------------------------------
Convener of the Numerical C Extensions Group (NCEG)
X3J11 member and US International Representative to ISO C (WG14)
----------------------------------------------------------------------------

rfg@NCD.COM (Ron Guilmette) (03/30/91)

In article <63.UUL1.3#5077@aussie.COM> rex@aussie.COM (Rex Jaeschke) writes:
+Dave Yost asks:
+
+> #ifdef PROTO
+> #define decl_args(x) x
+> #else
+> #define decl_args(x) ()
+> #endif
+> 
+> Are there any standards for what to call this 'decl_args' macro?
+
+If you are an implementer I have seen only __ used as the name. As a user, 
+I use xx. It's short and not too distracting allowing you to still read the 
+function declaration around it.

I have also seen a single underscore used (in system files).

In general, I wish that it were not even possible to misuse the preprocessor
in this manner.  Usage such as this will drive my protoize & unprotoize
tools bonkers.  If you avoid such usage however, protoize and & unprotoize
can be used to switch your code from one form to the other (i.e. prototyped
to unprototypes) and vise versa in the blink of an eye.

Well... maybe not quite THAT fast, but you get the idea.
-- 

// Ron ("Shoot From The Hip") Guilmette
// Internet: rfg@ncd.com      uucp: ...uunet!lupine!rfg
// New motto:  If it ain't broke, try using a bigger hammer.