Re: Cannot compile with _FILE_OFFSET_BITS = 64



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
.



Relevant Pages

  • compile error on alpha - binutils problem?
    ... {standard input}:246: Error: macro requires $at register while noat in effect ... # PCCARD support ...
    (Linux-Kernel)
  • Re: New Ethiopian Find - Oldest Biped At 3.8-4 mya
    ... >> This is not an example of a double standard. ... > criticise arguments you don't support for not ... *elimination of human hair as it relates to swimming. ... primarily--neither set out to address hair reduction) required a rather ...
    (sci.anthropology.paleo)
  • Re: So, they started synthesizing shared variables?
    ... The standard gives users something to ask your vendor to implement. ... in this case is not VHDL compliant. ... WRT support and not support, the 2004 approach is identical to the ... coding styles that would be accepted by a compliant synthesis tool. ...
    (comp.lang.vhdl)
  • Re: porting from C++Builder
    ... and I do believe that standard support of PME ... the java was growing and, obviously, microsoft initially tried to ...
    (microsoft.public.dotnet.languages.vc)
  • Re: calling convention stdcalll and cdecl call
    ... printf is defined in terms of fprintf. ... I don't have C89 standard handy at the moment, ... so a conforming C compiler has to support it. ... would be an improvement over cdecl. ...
    (microsoft.public.vc.language)