Kaz Kylheku wrote:

> santosh <(E-Mail Removed)> wrote:

>>

>> In K&R2 one exercise asks the reader to compute and print the

>> limits for the basic integer types. This is trivial for unsigned

>> types. But is it possible for signed types without invoking

>> undefined behaviour triggered by overflow? Remember that the

>> constants in limits.h cannot be used.

>

> You can use shifting to determine how many bits there are in the

> given signed integral type. Start with 1 and keep shifting it

> left until it drops off. With that information, you can construct
....

No, because the moment it 'drops off' you have run into

implementation (or undefined) behaviour. You can't write portable

code to do this. You can possibly write code that executes on YOUR

machinery.

--

[mail]: Chuck F (cbfalconer at maineline dot net)

[page]: <http://cbfalconer.home.att.net>

Try the download section.

--

Posted via a free Usenet account from

http://www.teranews.com