Re: pls expand this macro
- From: Park Sung-jae <darkpgm@xxxxxxxxxx>
- Date: Sun, 30 Oct 2005 22:50:42 +0900
sathyashrayan wrote:
> /*
> ** 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?
* the macro doesn't know the type of the variable.
if you expand the macro, it looks like this
case 1 / plural_text(0) : &"s"[0]
...
>
> 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"?
* "&" operand will make the right-side variable's pointer
so it makes the array of string which started from the index value
of the array..
>
> 3) << operator in the macro plural_text2 used to move the string to the
> second one, in the above case
> it is "s". Correct?
* << operator shifts the result of "(1==(n))",
so its last value is only be "0" or "2"
"0" will be the "es"
"2" will be the NULL
so you can see the boxes, or box
>
> Can any one explain both of the macros.
> --
> "combination is the heart of chess"
>
> A.Alekhine
>
> Mail to:
> sathyashrayan AT gmail DOT com
>
>
I'm poor at english.
- Park, Sung-jae
.
- References:
- pls expand this macro
- From: sathyashrayan
- pls expand this macro
- Prev by Date: Re: what does global char x[][444] mean?
- Next by Date: Re: Avaliable symbol table library??
- Previous by thread: pls expand this macro
- Next by thread: Re: pls expand this macro
- Index(es):
Relevant Pages
|