Re: Can I avoid "shift count is negative" warning? (involves template parameter)

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

 



Hello!

This might not apply to g++ 4.1.2, which is what you use, but I
don't have this version right here to test it.  It works fine for
gentoo's g++ 4.1.1 and produces no warnings:

template <int a>
int shift (int b)
{
	if (a > 0) {
		unsigned ua = a;
		return b >> ua;
	} else {
		unsigned ua = -a;
		return b << ua;
	}
}
template int shift<1>(int);
template int shift<-1>(int);

However, you will have to turn on optimization in order to get the
same efficient code than with your version (x86 here).

(I do get a warning for converting -1 to unsigned on g++ 3.4.6)

jlh

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux