On Nov 15, 2007 2:39 PM, debasish deka <[EMAIL PROTECTED]> wrote:
> I have read in K&R's C Programming and was trying for implementing token
> concatenation as follows:
>
> #define ONE 1
> #define TWO 2
>
> int main()
> {
> int i;
> printf("\nEnter the number\n");
> scanf("%d",&i);
> switch(i)
> {
> case(##ONE):
> printf("\nONE");
> break;
> case(##TWO):
> printf("\nTWO");
> break;
> default:
> printf("\nDefault\n");
> }
> system("PAUSE");
> return 0;
> }
##ONE and ##TWO will yield syntax errors -- you are not using token
pasting correctly. What do you think you are pasting together? Token
pasting is used inside of a pre-processor macro to combine two tokens
into a single token (which also must be valid). Your use here is
completely incorrect.
token concatenation was used a lot in the old days of C++ to create
pseudo-templates before real templates were part of the standard.
-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
If I were to divulge it, it would overturn the world."
-- Jelaleddin Rumi