Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

regarding system functions

Posted on 2004-07-30
10
Medium Priority
?
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Accepted Solution

by:
ssnkumar earned 80 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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

618 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