This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: FILE Pointer
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: Bharathi S <bharathi at lantana dot tenet dot res dot in>, GNU GCC <gcc-help at gcc dot gnu dot org>
- Date: Tue, 27 May 2003 11:22:37 -0500
- Subject: Re: FILE Pointer
- References: <5.2.1.1.0.20030527112143.009f21d0@pop.vt.edu>
Hi Bharathi,
>The sizeof(FILE) is 148 & sizeof(void) is 1. Does it mean anything ?
It means the struct FILE is 148 bytes long. And sizeof(void) is probably
calculated as if sizeof(char) -- probably something in the standard about that.
They could have done...
struct FILE {
char opaque[148];
};
...and thus...
sizeof(FILE) == 148
What's the sizeof(FILE*) & sizeof(void*)?
After all, you don't "malloc(sizeof(FILE))" or "new FILE" in the use of a
FILE*. You just use the FILE* returned by the fopen.
>and System dependent lib only can process the file descriptor ?
Which is why fileno(fp) will tell you the file descriptor. Along with all
the other functions I listed, which are the accessors to the FILE structure
information.
>I try to pass a void ptr to the ftell(), then I got the compilation error
"invalid use of void expression".
FILE* fp = fopen("foo.txt", "r");
void* vp = fp;
size_t position = ftell((FILE*)vp); // Don't forget your cast.
>With out casting, How it found that, ptr is NOT a type FILE ?
I'm not sure why you'd need to care, but you can use GCC's C++ language
extensions to test for type-ness.
Sincerely,
--Eljay