Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

define macro 1

Status
Not open for further replies.

billbose

Programmer
Jan 15, 2001
66
US
Code:
 #define is_dig(x) ((x) >= '0' && (x) <= '9')

Can somebody tell me what does the above macros mean?
 
Can't you at least make an educated guess as to what it means?

Have you considered say isdigit() function in ctype.h as a better alternative?

--
 
Sorry, if my question seemed vague. Its not about the digit, but the way the macro works. FYI. I am totally new to this macro thing.
I am trying to understand somebody else's code.
His code has the following:


Code:
#define is_dig(x) ((x) >= '0' && (x) <= '9') 
is_dig(pattern[c]) ;

To my understanding, the preprocessor replaces pattern[c] with

Code:
is_dig( (pattern[c]) >= '0' && (pattern[c]) << '9' ;

Is that right?
 
All occurances of
Code:
is_dig(pattern[c]);
will be replaced by:
Code:
(pattern[c]) >= '0' && (pattern[c]) <= '9';

Macros are like inline functions, except worse. You can't step through a macro while you're debugging and make finding and fixing bugs harder.
Functions or template functions are almost always better to use than macros.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top