Solved

regarding system functions

Posted on 2004-07-30
10
274 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

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 80
negation in C function 14 161
Linux context switch  - loop takes long time to process 6 128
smtp c source code 7 85
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 opening and reading files in the C programming language.

840 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