473,404 Members | 2,178 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,404 software developers and data experts.

what are these macros doing?

I'm trying to figure out if this code (which I'm sure was written for a C
compiler, could be considered legal C++. My confusion is from the last bit
of code at the end. Could someone explain to me what the reason for this
is?

#ifndef MAIN_H
#define MAIN_H

/*
* function prototype insulation
*/
#ifndef _
# ifdef __STDC__
# define _(x) x
# else
# define _(x) ()
# endif
#endif /* _ */

/*
* array manipulation
*/
#define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
#define ENDOF(a) ((a) + SIZEOF(a))

/*
* Take the define out of comments to debug
* the utilities.
* /
#define DEBUG
*/

#endif /* MAIN_H */

/* hexdump.h */

#ifndef HEXDUMP_H
#define HEXDUMP_H

#include <main.h>

void hexdump _((char *infile, char *outfile, long start, long finish,
int by_lines, int width, int no_ascii, int radix));

#endif /* HEXDUMP_H */

/* hexdump.c */
void
hexdump(infile, outfile, start, finish, by_lines, width, no_ascii, rdx)
char *infile;
char *outfile;
long start;
long finish;
int by_lines;
int width;
int no_ascii;
int rdx;
{
FILE *input;
FILE *output;
long addr;
long nlines;
int state;
int c;
unsigned char *line;
int addr_width;
int byte_width;
/*...*/
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 26 '05 #1
5 1286
> /* hexdump.c */
void
hexdump(infile, outfile, start, finish, by_lines, width, no_ascii, rdx)
char *infile;
char *outfile;
long start;
long finish;
int by_lines;
int width;
int no_ascii;
int rdx;
{
FILE *input;
FILE *output;
long addr;
long nlines;
int state;
int c;
unsigned char *line;
int addr_width;
int byte_width;
/*...*/


The last line is comment characters. Valid C and C++.
And the line before that is the declaration of a local variable of type int.

Stephen Howe

Stephen Howe
Jul 26 '05 #2
GB
Steven T. Hatton wrote:
I'm trying to figure out if this code (which I'm sure was written for a C
compiler, could be considered legal C++. My confusion is from the last bit
of code at the end. Could someone explain to me what the reason for this
is?

I assume you are asking about this:
#ifndef _
# ifdef __STDC__
# define _(x) x
# else
# define _(x) ()
# endif
#endif /* _ */
and this:
void hexdump _((char *infile, char *outfile, long start, long finish,
int by_lines, int width, int no_ascii, int radix));


The first sequence defines a macro named "_" that evaluates to its
argument if __STDC__ is defined and discards its argument if __STDC__ is
not defined.

It is then used to automatically discard the prototype arguments when
being compiled by a K&R C (pre-ANSI C) compiler, which does not have
prototypes. Notice the extra pair of parentheses that allow the whole
parameter list to be treated as a single macro argument.

Gregg
Jul 27 '05 #3
GB
GB wrote:
#ifndef _
# ifdef __STDC__
# define _(x) x
# else
# define _(x) ()
# endif
#endif /* _ */


The first sequence defines a macro named "_" that evaluates to its
argument if __STDC__ is defined and discards its argument if __STDC__ is
not defined.


Correction: it replaces its argument with a single pair of parentheses
if __STDC__ is not defined. It does not discard it.

Gregg
Jul 27 '05 #4
Steven T. Hatton wrote:
I'm trying to figure out if this code (which I'm sure was written for a C
compiler, could be considered legal C++. My confusion is from the last bit
of code at the end. Could someone explain to me what the reason for this
is?
I assume the part that is confusing is how the variable list is declared
for this function:
/* hexdump.c */
void
hexdump(infile, outfile, start, finish, by_lines, width, no_ascii, rdx)
char *infile;
char *outfile;
long start;
long finish;
int by_lines;
int width;
int no_ascii;
int rdx;
{


This is the now very old K&R syntax for function parameters. I believe
C99 removes this syntax from the grammar. I'm not sure if it is still
(or ever was) valid C++. In any case, this code can easily be rewritten
to follow the modern style by putting the parameter types before their
names, instead of in a separate list. There are likely tools available
that do that for you.

-Alan
Jul 27 '05 #5
Alan Johnson wrote:

I assume the part that is confusing is how the variable list is
declared for this function:
/* hexdump.c */
void
hexdump(infile, outfile, start, finish, by_lines, width, no_ascii,
rdx) char *infile;
char *outfile;
long start;
long finish;
int by_lines;
int width;
int no_ascii;
int rdx;
{


This is the now very old K&R syntax for function parameters. I
believe C99 removes this syntax from the grammar.

No, still valid. Still deprecated as well, but way too much prior code
written to remove support.

Implict function declarations have gone away though, so no more:

main()
{
}


Brian
Jul 27 '05 #6

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

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
21
by: Chris Reedy | last post by:
For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
7
by: Newbie_sw2003 | last post by:
Where should I use them? I am giving you my understandings. Please correct me if I am wrong: MACRO: e.g.:#define ref-name 99 The code is substituted by the MACRO ref-name. So no overhead....
6
by: Efim | last post by:
Hi all, Due to performance issue, I want to pevent execution of ToString() function in the code like the following: if(reporting_level & DEBUG_LEVEL) log(reporting_level,string.Format("Event of...
19
by: venkatesh.k.desai5 | last post by:
#define PI 3.12
3
by: PencoOdStip | last post by:
What are macros,virtual functions and what static means? I don't have time to read a book,i have to finish a simple plugin till tomorow morning to my first client and i need to know what these...
123
by: plenty900 | last post by:
I was looking over someone's C++ code today and despite having written perfectly readable C++ code myself, the stuff I was looking at was worse than legalese. The people who are guiding the...
4
by: Gestorm | last post by:
Hi all, I found a macro "USE_VAR" in the code of bash-3.2 as follows: /*file: bash-3.2/shell.c*/ 344 USE_VAR(argc); 345 USE_VAR(argv); 346 USE_VAR(env); 347 USE_VAR(code); 348 ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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...
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
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...
0
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...

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.