Solved

regarding system functions

Posted on 2004-07-30
10
257 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
New! My Passport Wireless Pro Wi-Fi Mobile Storage

Portable wireless storage to offload, edit, and stream anywhere.

High-capacity, wireless mobile storage designed to accompany professional photographers and videographers in the field to easily offload, edit and stream captured photos and high-definition videos.

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Statment to match two tables in c# 6 77
difference between mmap and malloc/valloc + mmap fixed 18 253
why "." vs "->" 23 119
Computer slow / BSOD 10 36
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…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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.
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.

929 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

12 Experts available now in Live!

Get 1:1 Help Now