[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: PATCH: getting rid of typeof(x)
From: Luis Coelho <luis.coelho () netc ! pt>
Date: 2001-02-02 13:57:38
[Download RAW message or body]
On Quinta, 1 de Fevereiro de 2001 19:41, Stefan Westerfeld wrote:
> > Hi!
>
> typeof(x) is a gcc extension, which works like this:
>
> int a;
> typeof(a) b; /* expands to int b; */
>
> I use that in kdelibs/arts/tests/test.h (only compiled when using make
> check), to prevent that the testEquals macro evaluates it's arguments
> twice.
>
> Since it is a gcc extension I probably shouldn't use it. So here is a patch
> that replaces it by a template based construct. I am not really proud of
> the new code, but it should do the same thing that the old code did.
>
> So if there are no objections/better ideas, I'll apply it.
>
> Cu... Stefan
I think you could do it with just a function:
template <typename T1, typename T2>
inline void checkEqualsFunction(const T1& v1, const T2& v2, const char* file,
int line, const char* expr1, const char* expr2)
{
if ( !(v1 == static_cast<T1>(v2)) ) {
fprintf (stderr,"\n %s::%s (%s:%d)\n",
currentClass, currentTest, file, line);
fprintf (stderr," => test assertion failed: (%s == %s)\n",expr1, expr2);
cerr << " => expected '" << v1 << "'" << " got "
<< "'" << v2 << "'." << endl;
exit(1);
}
}
#define testEquals(expr1,expr2) \
testsEqualsFunction((expr1),(expr2),__FILE__,__LINE__, #expr1,#expr2);
Why does it print to both stderr using fprintf and to cerr?
I am sorry I cannot present it as a patch, but I don't have the KDE source in
this computer.
Regards,
--
Luis Coelho.
Check out my game of Hearts, a card game, for KDE at:
http://www.geocities.com/deepblack9/index.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic