Re: Cannot compile with _FILE_OFFSET_BITS = 64
- From: roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson)
- Date: Mon, 31 Dec 2007 07:05:51 +0000 (UTC)
In article <fla6k1$j8h$1@xxxxxxxxxxxxx>, Scott.zhou <rwxrxrx@xxxxxxxxx> wrote:
25 if (lseek(fd, 4*1024*1024*1024, SEEK_SET) == -1) { // integer
overflow
The maximum int required to be supported in C is 32767. For any
constant integer expression that exceeds that, you need to use L or LL
or UL or ULL on the constants, such as 4L*1024L*1024L .
However, the maximum long required to be supported in C is 2**31-1
and 4*1024*1024*1024 exceeds that. You could naively true switching
to unsigned long, 4UL*1024UL*1024UL*1024UL but that would be 2**32
and the maximum unsigned long required to be supported in C is 2**32-1.
So, you will have to use a C99 compiler if you want to be sure of
being able to use a value of 4*1024*1024*1024 -- some C89 implementations
do provide large enough long or unsigned long, but relying on
that would not be portable. For portability you will need C99 and
to use long long or unsigned long long, 4LL*1024LL*1024LL*1024LL .
Next, you will need to somehow convert that value
4LL*1024LL*1024LL*1024LL into the type expected for that parameter
by lseek. lseek is not part of the C standard, so the C standard
does not say what that parameter should be. The particular machine
I looked at a moment ago documents its particular lseek as expecting
off_t . I do not happen to recall at the moment whether off_t
is defined as being an arithemetic type or whether it might be
allowed to be a non-arithmetic type such as a structure. You will
need to investigate that. The manual page you showed an excerpt of
defined off_t as an arithmetic type, but that might only happen
to be the case on that particular system; if you are following some
standard or other beyond C (e.g., POSIX) then if you want portability
to other systems that support that particular standard, you will
need to follow what that standard says, not what your local man page
says.
_FILE_OFFSET_BITS and most of the routines you call upon in
your program are not part of the C standard. For the proper use
of those functions, you will need to consult a newsgroup specific
to your system. The only reason that I answered your question
here is that it happens that 4*1024*1024*1024 is a construct
analyzable with respect to what -is- specified for the C language.
--
"History is a pile of debris" -- Laurie Anderson
.
- Prev by Date: Re: Programming in standard c
- Next by Date: Re: Programming in standard c
- Previous by thread: Re: Cannot compile with _FILE_OFFSET_BITS = 64
- Next by thread: Re: Cannot compile with _FILE_OFFSET_BITS = 64
- Index(es):
Relevant Pages
|