help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GURU NEEDED : macro SQUARE(x) for any type x


From: PKM
Subject: Re: GURU NEEDED : macro SQUARE(x) for any type x
Date: Fri, 14 Jan 2011 18:24:36 -0800 (PST)
User-agent: G2/1.0

On Jan 13, 11:46 pm, bolega <gnuist...@gmail.com> wrote:
> #define SQR(x) ({typedef xtype=x; xtype xval=x; xval*xval})  // NOTE,
> closure or {} inside () is a valid idea in C, and thus no return is
> needed.

I don't see how this could possibly work:

/*test.c*/
#define SQR(x) ({typedef xtype=x; xtype xval=x; xval*xval})

int main(void)
{
        SQR(2);
        return 0;
}

$ gcc test.c
test.c: In function ‘main’:
test.c:7: error: typedef ‘xtype’ is initialized (use __typeof__
instead)
test.c:7: error: expected ‘;’ before ‘}’ token

Recompiling after making those changes yields

test.c: In function ‘main’:
test.c:7: error: expected ‘(’ before ‘xtype’
test.c:7: error: ‘xtype’ undeclared (first use in this function)
test.c:7: error: (Each undeclared identifier is reported only once
test.c:7: error: for each function it appears in.)
test.c:7: error: expected ‘;’ before ‘xval’
test.c:7: error: ‘xval’ undeclared (first use in this function)

And even if it did compile, isn't it the case that
this code is attempting to use the same token as both
a value and as a type?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]