Solved

regarding system functions

Posted on 2004-07-30
10
248 Views
Last Modified: 2010-04-15
hi,

 If i want to use an C library i should include an header file in my C file.If i want to use a
System function in unix like open,read,write is it necessary to include a header file?
For sytem functions will it be automatically loaded or some may need header files?
0
Comment
Question by:pigeon7778
10 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11674285
Hi pigeon7778,
> System function in unix like open,read,write is it necessary to include a header file?
> For sytem functions will it be automatically loaded or some may need header files?

you will need header files ... check the man pages "synopsis" section to determine which files to include

Sunnycoder
0
 
LVL 33

Expert Comment

by:hongjun
ID: 11674290
they need header files.
See open() example
http://www.qnx.com/developers/docs/qnx_6.1_docs/neutrino/lib_ref/o/open.html

From there, you can find many other function calls.

hongjun
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 11674985
Pigeon7778,

When you #include a header you are not actually including the code it referrs to. Generally, all you are doing is reminding your module of the interface to those functions such as parameter positioning etc. It is the link phase that actually inserts the required code.

Paul
0
 
LVL 8

Accepted Solution

by:
ssnkumar earned 20 total points
ID: 11675168
It is the rule of the language which makes you add header files.

The rule of C language says that, when you want to use a variable or function, it should be declared before its use. If not, it will not be able to tell the type of the variable (return type and type of parameters in case of functions) and hence will not be able to do the syntax checking.
Hence it expects a forward declaration of every variable and function.

This is what is header file used for. It contains the declarations of all the functions and declrations/definition of variables, types and structures.
The actual definition may lay somewhere else (most probably in a library which is a .so or .a file)
During linking these libraries will be linked. So, the compiler cannot wait till linking time for syntax checking. Hence the declarations will be placed in a header file so that compilation goes thru.

Hence, both in case of library functions and system calls, inclusion of header file is mandatory.

Hope it is clear now.....

-ssnkumar
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 11675171
Conclusion: you don't need header-files if you don't want to. They just come in very handy, for the C-compiler needs a definition of an external function before it can be used, in order to do some type-checking. Take your manual and define the systemcalls yourself.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 11675180
(Should I stick around to wait for the walls coming down on me??)
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 11675221
>>(Should I stick around to wait for the walls coming down on me??)

Yes! You've just deeply confused a budding programmer by suggesting one of the worst programming practices there is. May you forever live in interesting times :)~

Paul
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 11675315
(As the Chinese saying goes...)

Oops, that hurts. Dear Pigeon7778, please use in 100% of your programming the include-files supplied with your compiler or system. We won't confuse you with the reasons why, unless you want to know.

Paul, it's very interesting over here! :)
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 11675616
Or the 'full' version of the (perhaps scottish) curse:

May you live in interesting times and attract the attention of important people and may all your dreams come true.

http://hawk.fab2.albany.edu/sidebar/sidebar.htm

Paul
0
 

Author Comment

by:pigeon7778
ID: 11714530
Thanks a lot everyone.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now