473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need of type "FILE"

I am not an expert in C, but from all the C code I've seen in my last
4yrs of coding in C, I observe that programmers only use only "FILE *"
type and never the actual "FILE" type. So my question is :

<1what is the actual use of this structure; i.e. can it be used
anywhere in general programming? It is of course a very important
structure, but can we make use of it a standard C program? I am told
that using internals of this structure is not encouraged.

<2instead of having,
typedef struct _iobuf
{
char* _ptr;
int _cnt;
char* _base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char* _tmpfname;
} FILE;
the stdio.h could have contained a type "pointer to FILE". This would
save us writing the * every time.
Dec 2 '07 #1
3 2986
BiGYaN wrote:
I am not an expert in C, but from all the C code I've seen in my last
4yrs of coding in C, I observe that programmers only use only "FILE *"
type and never the actual "FILE" type. So my question is :

<1what is the actual use of this structure; i.e. can it be used
anywhere in general programming? It is of course a very important
structure, but can we make use of it a standard C program? I am told
that using internals of this structure is not encouraged.
That's correct. The details of the FILE type are implementation specific
and any code that manipulates or otherwise relies on them will be tied
to a particular implementation.

Moreover the Standard library proved a full suite of functions to
manipulate streams and there is nothing to be gained by messing around
with implementation secrets.
<2instead of having,
typedef struct _iobuf
{
char* _ptr;
int _cnt;
char* _base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char* _tmpfname;
} FILE;
the stdio.h could have contained a type "pointer to FILE". This would
save us writing the * every time.
No, I prefer some semblance of transparency in the source code.
Excessive use of typedefs make the code very opaque. If an object is a
pointer type then I want to know about it.

Dec 2 '07 #2
BiGYaN wrote:
I am not an expert in C, but from all the C code I've seen in my last
4yrs of coding in C, I observe that programmers only use only "FILE *"
type and never the actual "FILE" type. So my question is :

<1what is the actual use of this structure; i.e. can it be used
anywhere in general programming? It is of course a very important
structure, but can we make use of it a standard C program? I am told
that using internals of this structure is not encouraged.
That is correct. The internals of this structure are the sole concern of
the stdio library. You should never modify them. It is occasionally
useful to examine the internals for debugging purposes, but only if
you're pretty familiar with what they mean, which is highly
implementation-specific.
<2instead of having,
typedef struct _iobuf
{
char* _ptr;
int _cnt;
char* _base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char* _tmpfname;
} FILE;
the stdio.h could have contained a type "pointer to FILE". This would
save us writing the * every time.
That's certainly true, but experience has shown that typedefs for
pointer types often lead to confusion. They are pointers, and behave
like pointers, but don't obviously look like pointers.
Dec 2 '07 #3
Thank you both santosh and James Kuyper. Your answers enforced my
beliefs further.

But on the typedef for FILE * is something that I am not much
convinced about .... I guess it is ultimately a matter of personal
preference.

Dec 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Pastrovick | last post by:
Is there a way to load an image locally (in the client) when a selection of a file is made using input type=file. The purpose is to allow selection of a file and put the image in the browser...
1
by: Mark Sandfox | last post by:
Is there a way to restrict the user to only selecting and sending either a ..gif or .jpg. Everything I have read says this option can not be done by design (security reasons). I find that irronic...
2
by: IkBenHet | last post by:
Hello, I am uploading a file using this form in ASP.NET. I have also added a simpel textfield: <form runat="server" enctype="multipart/form-data"> <input type="file" id="oFile" Name="oFile"...
2
by: mark | last post by:
How do I detect that a particular form element is a file upload or if the file upload has worked? In the Python cgi module documentation I found suggested code... form = cgi.FieldStorage()...
9
by: Prakash Singh Bhakuni | last post by:
am replacing the default "Browse..." button for input type=file. This works fine except that the form will only submit after the SUBMIT button is clicked twice. Any ideas on why this is happening...
2
by: trint | last post by:
With the following code, I get the "message" whether or not there is content in my filefield: function check_file_field() { var file_field = document.getElementById("custCartFile");...
12
by: menmysql | last post by:
hi i want to dispaly an image on my webpage which is selected using <input type="file">. is it possible. please reply urgent ...
9
by: Roger Withnell | last post by:
I am building a website in Russian. What options do I have to make the "Browse" button display in other languages? Thanking you in anticipation. Posted Via Usenet.com Premium Usenet...
1
by: sandeep kumar shah | last post by:
Hi, We have used a file uploading HTML tag in an HTML page. We need to customize the text displayed on the Button (which is by default “Browse…” for internet explorer). Below is the...
6
by: passionateforjava | last post by:
Hi All, I am using struts application wherein I need to import file for some purpose.I have used input type="file" for the same which goes like: <input type="file" id="uploadFile" name="uploadFile"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.