Re: Cannot compile with _FILE_OFFSET_BITS = 64



On Mon, 31 Dec 2007 11:55:18 -0500, Joe Wright wrote:
Ulrich Eckhardt wrote:
Richard Tobin wrote:
In article <5truv2F1f3un6U1@xxxxxxxxxxxxxxxxx>, Ulrich Eckhardt
<doomster@xxxxxxxx> wrote:
lseek64(fd, 4*1024*1024*1024, SEEK_SET) // integer overflow
Others already explained what is happening, but I'd suggest another
approach that works without C99's long long type simply cast the
expression to off_t, which will automatically be the correct 64 bit
type, regardless of whether you use C89 or C99.
Casting the expression won't help, if it's already overflowed as an
int.

Argh, well caught. Casting the first constant in above expression does
the job though.

You presume the first expression (4) will be evaluated before the last
(1024). Why?

(off_t)4*1024*1024*1024
is equivalent to
(((((off_t)4)*1024)*1024)*1024)
regardless of which constant is evaluated first. The compiler is
certainly allowed to evaluate the expression right-to-left (or any other
order), but the last 1024 is multiplied by an expression of type off_t,
so the multiplication still happens in off_t arithmetic.
.



Relevant Pages

  • Re: The weak Men of Europe
    ... Enemy at the Gates is regardless of casting a superb war movie. ... worth seeing if you haven't watched it yet. ...
    (soc.culture.irish)
  • Re: True could not be set on property
    ... regardless of the actual value. ... original code was casting the value to a Boolean. ... the cast to result in True, but no value would cause False? ...
    (microsoft.public.dotnet.framework.aspnet)