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: James Kuyper
Subject: Re: GURU NEEDED : macro SQUARE(x) for any type x
Date: Fri, 14 Jan 2011 06:13:06 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7

On 01/14/2011 03:51 AM, Gert-Jan de Vos wrote:
On Jan 14, 7:46�am, bolega<gnuist...@gmail.com>  wrote:
Basically, I have spent a few hours experimenting and searching on the
comp.lang.c/c++

Let me use SQR for brevity and saving line

Here are progressively refined macros :

#define SQR(x) ((x)*(x))

#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.

this macro is given in several posts like

http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/38ef2...

there is a problem with typedef

Bolega

Why not just an inline function template (this being c.l.c++)?

template<typename T>
inline T square(T value)
{
     return value*value;
}

Because this is also cross-posted to c.l.c. That could mean he's one of those people who thinks C and C++ are a single language called C/C++, but alternatively, it could mean that he needs a separate solution for each language, or a single solution that works in both languages.



reply via email to

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