[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: always true warning
From: |
Hallvard B Furuseth |
Subject: |
Re: always true warning |
Date: |
Sat, 23 Dec 2006 14:04:14 +0100 |
Mehturt@gmail.com writes:
> What I did is I implemented template fn bool isnegative() which is used
> instead of <0.
> This fn returns false in general and is specialized for signed types so
> that it returns <0.
In GNU C I'd use
#define isnegative(i) \
((__typeof__(i))-1 < 1 && (i) < (__typeof__(i)) ((__typeof__(i))-1 > 0))
For unsigned types it becomes (false && ...skipped...)
For signed types, (true && (i) < (__typeof__(i))false).
Possibly the (__typeof(i)__) cast can be skipped without provoking any
warnings, I'm not sure.
Maybe there is a C++ way to do something similar, without using a Gnu
extension.
--
Hallvard