Solved

regarding system functions

Posted on 2004-07-30
10
286 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
Technology Partners: 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!

 
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
 
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

Technology Partners: 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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

691 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