[Top][All Lists]

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

Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..."

From: Thomas Neumann
Subject: Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..."
Date: Fri, 29 Dec 2006 21:06:58 +0100
User-agent: Thunderbird (X11/20061115)

> For this _specific_ instance of the general problem, C++ users could
> use numeric_limits<time_t>::max() and get away with it, but I don't
> believe such a solution (or the one you propose or similar I've seen)
> to this specific instance generalizes to portable, readable and
> maintainable solution to the general problem.   
while a solution that is a generic as numeric_limits is hard to do in C,
a simple calculation of the larges positive value can be done in C:

#define MAXSIGNEDVALUE(x) (~((~((x)0))<<(8*sizeof(x)-1)))

admittedly this simple definition still overflow during constant folding
(see below for a more complex one that avoid this), but you can
calculate the maximum value with a not too complex macro.

This should be enough for most use cases; if you need defined overflows,
use unsigned data types. And in the rare cases that this might not be
possible, use autoconf magic to find out the types/constants you have to
use. Your code will not be portable to other compilers anyway.
Restricting the optimizer by default just for these obscure corner cases
does not seem justified IMHO, especially if other compilers behave the same.


Longer definition that avoids undefined overflows:

#define MAXSIGNEDVALUE(x) ((x)(~((~((unsigned long \

reply via email to

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