pls expand this macro




/*
** 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


.



Relevant Pages

  • Re: S-expr form of C
    ... rpw3@xxxxxxxx (Rob Warnock) writes: ... and have macros defined to build these CLOS ... to ground such an effort firmly in some concrete syntax which *can* ... (let ((av int) ...
    (comp.lang.lisp)
  • Re: [PATCH] WARN_ONCE(): use bool for boolean flag
    ... Yes, it could (as long as either it is converted back to int in the return of the macro, or all users do not care about the macro's return type). ... text data bss dec hex filename ... conditionals it drops it by another 84 bytes. ... Besides, the unlikelyall these macros end with does a double negation, meaning even if it is an int, it will be either 0 or 1 into likely). ...
    (Linux-Kernel)
  • Type name style was Re: rolling dice
    ... } DICEROLL; ... I strongly advocate the use of ALL CAPS for macros and for macros only. ...
    (comp.lang.c)
  • Re: Using multiple defines!
    ... int *A2, ... //aGMI declared in header ... Leave ALL_UPPERCASE for macros and use only that for all macros. ... wanted to declare everything at the top with define statements. ...
    (microsoft.public.vc.language)
  • Re: [KJ] Re: [PATCH] drivers/isdn/hisax: ARRAY_SIZE instead of sizeof
    ... are assigned to preprocessor macros. ... int __init ... static void ...
    (Linux-Kernel)