Re: Macros




Peter "Shaggy" Haywood wrote:
Groovy hepcat Walter Roberson was jivin' on Tue, 28 Nov 2006 07:57:39
+0000 (UTC) in comp.lang.c.
Re: Macros's a cool scene! Dig it!

In article <1164698162.284936.137360@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Harry <gehariprasath@xxxxxxxxx> wrote:

I have a piece of code as

# define prod(a,b)=a*b
main()
{
int x=2;
int y=3;
printf("%d",prod(x+2,y-10));
}

will the macro be evaluated as (2+2)*(3-10)=4* -7 =-28.

No, each dummy argument will be *textually* dropped into place exactly
as specified. Thus, your line would expand to

printf("%d",x+2*y-10);

No, it would expand to this:

printf("%d",=x+2*y-10);

which is a syntax error.

- don't use = in the macro definition

Exactly.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?



Sorry guys,that = is not present in the maro expansion.It was my
mistake & thanks for clearing the doubt.

.



Relevant Pages

  • Re: Macros
    ... Harry wrote: ... int x=2; ... your line would expand to ... Dig the even newer still, yet more improved, sig! ...
    (comp.lang.c)
  • Re: main return value stange question
    ... value (relying on implicit int), ... Now we know it won't compile, ... Dig the even newer still, yet more improved, sig! ...
    (comp.lang.c)
  • Re: Colon (:) syntax in defining fields in a struct
    ... of signed int, unsigned int or _Bool are portable. ... Dig the even newer still, yet more improved, sig! ... "Ain't I'm a dog?" ...
    (comp.lang.c)
  • Re: accessing an array outside its bounds
    ... int main ... NASA via your modem and cause NASA computers to reprogram the Mars ... door, knock, wait for you to answer the door and then give you a smack ... Dig the even newer still, yet more improved, sig! ...
    (comp.lang.c)
  • Re: Newbie Problem
    ... arithmetic, equity and relational operators, and the "if" statement to ... three numbers by first finding the largest of two of them, ... int max ... Dig the even newer still, yet more improved, sig! ...
    (comp.lang.c)