----- Original Message -----
From: "basha_ram_id"
To:
Sent: Tuesday, April 27, 2004 6:51 PM
Subject: [UTTARA] (query) doubts on symbolic literals
hi vijay! i have few doubts as follows.
#define ISDIGIT(c) ((unsigned)((c)-'0')<10)
#define ISALPHA(c) ((unsigned)(((c)|32)-'a')<26)
#define ISALNUM(c) (ISDIGIT(c)||ISALPHA(c))
#define min(a,b) ((a)<(b)?(a):(b))
#define ARRAYSIZE(a) (sizeof(a)/sizeof((a)[0]))
((unsigned)((c)-'0')<10) here what this ((c)-'0') stands for.
(((c)|32)-'a')<26) here what this ((c)|32)-'a') stands for.
(sizeof(a)/sizeof((a)[0])) here sizeof((a)[0]) mean ?
TIA
regards
basha
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The macros ISALPHA, ISDIGIT, and ISALNUM test the character passed. The
underlying character set of the machine could be either ASCII, EBCDIC, or
relatively new known as Unicode.
Googling "define: ASCII" gives the definition:
This is the de facto world-wide standard for the code numbers used by
computers to represent all the upper and lower-case Latin letters,
numbers, punctuation, etc. There are 128 standard ASCII codes each of
which can be represented by a 7 digit binary number: 0000000 through
1111111, plus parity.
Googling "define: EBCDIC" gives the definition:
Extended Binary-Coded Decimal Interchange Code. A group of coded
character sets used on mainframes that consist of 8-bit coded
characters. EBCDIC coded character sets reserve the first 64 code
positions (x00 to x3F) for control codes, and reserve the range
x41 to xFE for graphic characters. The English alphabetic characters
are in discontinuous segments with uppercase at xC1 to xC9, xD1 to xD9,
xE2 to xE9, and lowercase at x81 to x89, x91 to x99, xA2 to xA9.
Following points can be noted about ASCII and EBCDIC:
* Numbers have contiguous codes.
* Alphabetic characters in ASCII are contiguous, while in EBCDIC they
are not.
>
> #define ISDIGIT(c) ((unsigned)((c)-'0')<10)
The expression ((c)-'0') finds the offset of the character "c" from number zero.
If the offset is less than 10, then "c" is a number.
> #define ISALPHA(c) ((unsigned)(((c)|32)-'a')<26)
The expression ((c)|32)-'a') is interesting. It assumes the character set to
be ASCII, and hence nonportable. The expression (c)|32 converts "c" to lower
case since we are subtracting 'a'; the difference is compared with 26 since
there are 26 alphabets. See question 23 of my FAQ page to know about ASCII
case conversion.
The following function is portable.
#inlcude
int
to_lower ( int c )
{
static const char * const lower = "abcdefghijklmnopqrstuvwxyz";
static const char * const upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const char * ptr = 0;
ptr = strchr ( upper, c );
return ptr ? (int)lower[ptr-upper] : c;
}
> #define ISALNUM(c) (ISDIGIT(c)||ISALPHA(c))
> #define min(a,b) ((a)<(b)?(a):(b))
Pass.
> #define ARRAYSIZE(a) (sizeof(a)/sizeof((a)[0]))
>
((a)[0]) is a syntactic sugar; (See
http://www.catb.org/~esr/jargon/html/S/syntactic-sugar.html)
it is equivalent to (a[0]), because
((a)[0]) == *((a) + 0)
(a[0]) == *(a + 0) are same.
The other point is that the programmer followed ethics since he sorrounded the
macro argument by parantheses!
               (
geocities.com/vijoeyz/faq)                   (
geocities.com/vijoeyz)