logo       

Re: FILE Pointer: msg#00252

gcc.help

Subject: Re: FILE Pointer

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




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise