pls expand this macro
- From: sathyashrayan <sathyashrayan@xxxxxxxxxxxxxxxxxxx>
- Date: Sun, 30 Oct 2005 18:55:14 +0530
/*
** PLURALTX.C - How to print proper plurals
** public domain - original algorithm by Bob Stout
*/
#include <stdio.h>
#define plural_text(n) &"s"[(1 == (n))]
#define plural_text2(n) &"es"[(1 == (n))<<1]
int main(void)
{
int i;
for (i = 0; i < 10; ++i)
printf("%d thing%s in %d box%s\n", i, plural_text(i), i,
plural_text2(i));
return 0;
}
My questions:
1) I try to understand the two macros plural_text and plural_text2.
array subscripting is commutative
so in the above we could expand the macros as plural_text n[1] = "s" .
The parenthesis around
the variable (n) since the macros does not know the type of the variable
it is acting on. Am I correct?
2) I don't able to understand the use of & in both of the macros. Does
it used for the rule "array decays into
the pointer to it's first element"?
3) << operator in the macro plural_text2 used to move the string to the
second one, in the above case
it is "s". Correct?
Can any one explain both of the macros.
--
"combination is the heart of chess"
A.Alekhine
Mail to:
sathyashrayan AT gmail DOT com
.
- Follow-Ups:
- Re: pls expand this macro
- From: Simon Biber
- Re: pls expand this macro
- From: Walter Roberson
- Re: pls expand this macro
- From: Park Sung-jae
- Re: pls expand this macro
- Prev by Date: Binary Search
- Next by Date: Re: "a < b < c" not the same as "(a < b) && (b < c)"?
- Previous by thread: Binary Search
- Next by thread: Re: pls expand this macro
- Index(es):
Relevant Pages
|