|
From: Julien Darthenay <julie...@la...> - 2009-03-24 22:18:45
|
Hi everybody, I had a problem reading a big file (more then 2 gigabytes) because I need to use fseek() and ftell() to do what I want with it. I've been told about the long long data type which I didn't know it exists and the fseeko() and ftello() functions. I've seen there is no fseeko() function in my stdio.h, but there is a fseeko64() function and a ftello64() function which should be what I need. But their definitions are optionnal and depend of my #defines. Which #define should I add in my source code (or -D option in my makefile) in order to use these functions without any warning ? My Mingw runtime is : mingwrt-3.15.1-mingw32.tar.gz My OS is Windows XP SP2. Thanks for your help. Julien Darthenay |
|
From: Greg Chicares <gchic...@sb...> - 2009-03-25 02:24:56
|
On 2009-03-24 22:18Z, Julien Darthenay wrote: > > I had a problem reading a big file (more then 2 gigabytes) because I > need to use fseek() and ftell() to do what I want with it. I've been > told about the long long data type which I didn't know it exists and the > fseeko() and ftello() functions. I've seen there is no fseeko() function > in my stdio.h, but there is a fseeko64() function and a ftello64() > function which should be what I need. But their definitions are > optionnal and depend of my #defines. Which #define should I add in my > source code (or -D option in my makefile) in order to use these > functions without any warning ? Here's an fseeko64() testcase that is said to need no '-D' option: http://article.gmane.org/gmane.comp.gnu.mingw.user/28881 Does it work for you? If that doesn't lead to an answer, then post a minimal standalone testcase of your own, copying and pasting any diagnostics you observe when compiling it. |
|
From: Julien Darthenay <julie...@la...> - 2009-03-25 22:36:27
|
Greg Chicares a écrit : > On 2009-03-24 22:18Z, Julien Darthenay wrote: > >> I had a problem reading a big file (more then 2 gigabytes) because I >> need to use fseek() and ftell() to do what I want with it. I've been >> told about the long long data type which I didn't know it exists and the >> fseeko() and ftello() functions. I've seen there is no fseeko() function >> in my stdio.h, but there is a fseeko64() function and a ftello64() >> function which should be what I need. But their definitions are >> optionnal and depend of my #defines. Which #define should I add in my >> source code (or -D option in my makefile) in order to use these >> functions without any warning ? >> > > Here's an fseeko64() testcase that is said to need no '-D' option: > http://article.gmane.org/gmane.comp.gnu.mingw.user/28881 > Does it work for you? If that doesn't lead to an answer, then post > a minimal standalone testcase of your own, copying and pasting any > diagnostics you observe when compiling it. > > ------------------------------------------------------------------------------ > Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are > powering Web 2.0 with engaging, cross-platform capabilities. Quickly and > easily build your RIAs with Flex Builder, the Eclipse(TM)based development > software that enables intelligent coding and step-through debugging. > Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com > This don't work. I get the following warnings : (I created the fseeko64.c file to test this sample code) fseeko64.c:15: warning: implicit declaration of function `fileno' fseeko64.c:22: warning: implicit declaration of function `fseeko64' fseeko64.c:23: warning: implicit declaration of function `ftello64' You can't reasonably use a function with a warning and expect it to work. |
|
From: Greg Chicares <gchic...@sb...> - 2009-03-26 00:51:25
|
On 2009-03-25 22:36Z, Julien Darthenay wrote: > Greg Chicares a écrit : >> On 2009-03-24 22:18Z, Julien Darthenay wrote: >> >>> I had a problem reading a big file (more then 2 gigabytes) because I >>> need to use fseek() and ftell() to do what I want with it. I've been >>> told about the long long data type which I didn't know it exists and the >>> fseeko() and ftello() functions. I've seen there is no fseeko() function >>> in my stdio.h, but there is a fseeko64() function and a ftello64() >>> function which should be what I need. But their definitions are >>> optionnal and depend of my #defines. Which #define should I add in my >>> source code (or -D option in my makefile) in order to use these >>> functions without any warning ? >> >> Here's an fseeko64() testcase that is said to need no '-D' option: >> http://article.gmane.org/gmane.comp.gnu.mingw.user/28881 [...] > This don't work. I get the following warnings : (I created the > fseeko64.c file to test this sample code) > fseeko64.c:15: warning: implicit declaration of function `fileno' > fseeko64.c:22: warning: implicit declaration of function `fseeko64' > fseeko64.c:23: warning: implicit declaration of function `ftello64' I copied the testcase directly from Tor's message, and I didn't get those warnings. Here's what I see with fairly finicky warning options, expressly including '-Wimplicit': $/MinGW_/bin/gcc -Wall -W -pedantic -Wimplicit -c fseeko64.c fseeko64.c:22:16: warning: use of C99 long long integer constant fseeko64.c: In function `main': fseeko64.c:23: warning: ISO C does not support the `I64' printf length modifier fseeko64.c:25: warning: ISO C does not support the `I64' printf length modifier fseeko64.c:32:16: warning: use of C99 long long integer constant fseeko64.c:33: warning: ISO C does not support the `I64' printf length modifier fseeko64.c: At top level: fseeko64.c:9: warning: unused parameter 'argc' fseeko64.c:9: warning: unused parameter 'argv' That's with MinGW gcc-3.4.4, but I also tried 3.4.5 and 4.3.0, and didn't see any of the warnings you reported. Are you using different compiler options? |
|
From: Julien Darthenay <julie...@la...> - 2009-03-26 11:41:09
|
Greg Chicares a écrit : > On 2009-03-25 22:36Z, Julien Darthenay wrote: > >> Greg Chicares a écrit : >> >>> On 2009-03-24 22:18Z, Julien Darthenay wrote: >>> >>> >>>> I had a problem reading a big file (more then 2 gigabytes) because I >>>> need to use fseek() and ftell() to do what I want with it. I've been >>>> told about the long long data type which I didn't know it exists and the >>>> fseeko() and ftello() functions. I've seen there is no fseeko() function >>>> in my stdio.h, but there is a fseeko64() function and a ftello64() >>>> function which should be what I need. But their definitions are >>>> optionnal and depend of my #defines. Which #define should I add in my >>>> source code (or -D option in my makefile) in order to use these >>>> functions without any warning ? >>>> >>> Here's an fseeko64() testcase that is said to need no '-D' option: >>> http://article.gmane.org/gmane.comp.gnu.mingw.user/28881 >>> > [...] > >> This don't work. I get the following warnings : (I created the >> fseeko64.c file to test this sample code) >> fseeko64.c:15: warning: implicit declaration of function `fileno' >> fseeko64.c:22: warning: implicit declaration of function `fseeko64' >> fseeko64.c:23: warning: implicit declaration of function `ftello64' >> > > I copied the testcase directly from Tor's message, and I didn't > get those warnings. Here's what I see with fairly finicky warning > options, expressly including '-Wimplicit': > > $/MinGW_/bin/gcc -Wall -W -pedantic -Wimplicit -c fseeko64.c > fseeko64.c:22:16: warning: use of C99 long long integer constant > fseeko64.c: In function `main': > fseeko64.c:23: warning: ISO C does not support the `I64' printf length modifier > fseeko64.c:25: warning: ISO C does not support the `I64' printf length modifier > fseeko64.c:32:16: warning: use of C99 long long integer constant > fseeko64.c:33: warning: ISO C does not support the `I64' printf length modifier > fseeko64.c: At top level: > fseeko64.c:9: warning: unused parameter 'argc' > fseeko64.c:9: warning: unused parameter 'argv' > > That's with MinGW gcc-3.4.4, but I also tried 3.4.5 and 4.3.0, > and didn't see any of the warnings you reported. Are you using > different compiler options? > > ------------------------------------------------------------------------------ > Hi, I've just discovered a way to solve the warnings problem. I added the following directive before including <stdio.h> : #undef __STRICT_ANSI__ I don't know why __STRICT_ANSI__ is defined even when I don't use the -ansi option. My makefile contains the following flags : CFLAGS = -Wformat -Wall -std=c99 LDFLAGS = -lcomctl32 UNICODEFLAGS = -DUNICODE -D_UNICODE -finput-charset=iso-8859-1 |
|
From: Greg Chicares <gchic...@sb...> - 2009-03-26 12:44:42
|
On 2009-03-26 11:40Z, Julien Darthenay wrote:
>
> I've just discovered a way to solve the warnings problem. I added the
> following directive before including <stdio.h> :
> #undef __STRICT_ANSI__
>
> I don't know why __STRICT_ANSI__ is defined even when I don't use the
> -ansi option. My makefile contains the following flags :
> CFLAGS = -Wformat -Wall -std=c99
You have specified the '-std=c99' option, but you're using
functions like fseeko64() that are not part of the C99 standard,
so you get a warning. (You could say that __STRICT_ANSI__ is a
misnomer: the compiler sets it for all '-std' options that
specify any ISO standard.)
That's actually the correct behavior. Consider:
#include <stdio.h>
void foo(void);
int main() {foo(); return 0;}
That's a strictly-conforming C99 program if you replace 'foo'
with any name that C99 does not reserve, including 'fseeko64',
so 'gcc -std=c99' must accept that program.
Of course, that behavior is inconvenient when you want to use
extensions like fseeko64(). Options, from worst to best IMO:
(1) Don't use '-std='. But then you may not get other valuable
diagnostics that you really do want.
(2) Prototype all extra functions yourself.
(3) Manipulate __STRICT_ANSI__.
(4) Use a different '-std=' setting if possible.
In this case, '-std=gnu99' works, and that's probably the best
option. (Where it doesn't work, I prefer (3) myself.)
|
|
From: Julien Darthenay <julie...@la...> - 2009-03-26 17:03:43
|
Greg Chicares a écrit :
> On 2009-03-26 11:40Z, Julien Darthenay wrote:
>
>> I've just discovered a way to solve the warnings problem. I added the
>> following directive before including <stdio.h> :
>> #undef __STRICT_ANSI__
>>
>> I don't know why __STRICT_ANSI__ is defined even when I don't use the
>> -ansi option. My makefile contains the following flags :
>> CFLAGS = -Wformat -Wall -std=c99
>>
>
> You have specified the '-std=c99' option, but you're using
> functions like fseeko64() that are not part of the C99 standard,
> so you get a warning. (You could say that __STRICT_ANSI__ is a
> misnomer: the compiler sets it for all '-std' options that
> specify any ISO standard.)
>
> That's actually the correct behavior. Consider:
>
> #include <stdio.h>
> void foo(void);
> int main() {foo(); return 0;}
>
> That's a strictly-conforming C99 program if you replace 'foo'
> with any name that C99 does not reserve, including 'fseeko64',
> so 'gcc -std=c99' must accept that program.
>
> Of course, that behavior is inconvenient when you want to use
> extensions like fseeko64(). Options, from worst to best IMO:
> (1) Don't use '-std='. But then you may not get other valuable
> diagnostics that you really do want.
> (2) Prototype all extra functions yourself.
> (3) Manipulate __STRICT_ANSI__.
> (4) Use a different '-std=' setting if possible.
> In this case, '-std=gnu99' works, and that's probably the best
> option. (Where it doesn't work, I prefer (3) myself.)
>
> ------------------------------------------------------------------------------
>
Ok, but I had to add -std=c99 to have the long long type recognized,
wich is necessary to use fseeko64(). I tried with -std=gnu99 and it
worked perfectly, than you very much.
Julien Darthenay
|
|
From: Keith Marshall <keith...@us...> - 2009-03-26 18:38:20
|
On Wednesday 25 March 2009 22:36:10 Julien Darthenay wrote: > > Here's an fseeko64() testcase that is said to need no '-D' > > option: http://article.gmane.org/gmane.comp.gnu.mingw.user/28881 > > Does it work for you? If that doesn't lead to an answer, then > > post a minimal standalone testcase of your own, copying and > > pasting any diagnostics you observe when compiling it. > > This don't work. It does for me. > I get the following warnings : (I created the > fseeko64.c file to test this sample code) > fseeko64.c:15: warning: implicit declaration of function `fileno' > fseeko64.c:22: warning: implicit declaration of function `fseeko64' > fseeko64.c:23: warning: implicit declaration of function `ftello64' You must have compiled with `-ansi', or one of the `-std=...' options which implies `__STRICT_ANSI__'. None of the three functions above are required by ISO C99 (ANSI), and their prototypes are not exposed when you demand strict standards compliance. > You can't reasonably use a function with a warning and expect it to > work. You can, if you understand the warning sufficiently to deem it to be irrelevant; for example, I see much the same as Greg: $ gcc -pedantic -Wall -Wextra -c foo.c foo.c:21:16: warning: use of C99 long long integer constant foo.c: In function `main': foo.c:22: warning: ISO C does not support the `I64' printf length modifier foo.c:25: warning: ISO C does not support the `I64' printf length modifier foo.c:32:16: warning: use of C99 long long integer constant foo.c:33: warning: ISO C does not support the `I64' printf length modifier foo.c: At top level: foo.c:9: warning: unused parameter 'argc' foo.c:9: warning: unused parameter 'argv' Here we can safely ignore all of those warnings, because: 1) The C99 long long integer constant is passed as an argument to a function, where the prototype expects a `typedef long long'. 2) Our specific printf() implementation *does* support the `I64' length modifier. 3) It hardly matters that we never use the arguments to main(); (of course, it would be better to define it without any). That said, implicit declaration of a function is a warning which you should not simply ignore; you should provide a prototype, and in this case you can do that by *not* excluding non-ansi functions. -- Regards, Keith. |