Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Basic Question On C (http://www.go4expert.com/forums/basic-question-c-t4625/)

naiya 11Jun2007 18:18

Basic Question On C
Why are some functions defined in more than one header file? Like malloc() is defined in
malloc.h and alloc.h. And exit(0) is defined in process.h and stdlib.h,why?

shabbir 11Jun2007 19:12

Re: Basic Question On C
Because of semantic help.

DaWei 11Jun2007 22:18

Re: Basic Question On C
Same reason Merriam-Webster has a lot of the same words as the Oxford English dictionary. Maybe it's a waste, maybe not.

naiya 12Jun2007 09:03

Re: Basic Question On C

Originally Posted by shabbir
Because of semantic help.

Shabbir ,your answer didn't solve my problem.Because I didn't understand the meaning of semantic help. Plz ,can you explain this ?

shabbir 12Jun2007 10:25

Re: Basic Question On C
A function may be related to 2 operations.

Say stdlib have functions for standard library function and say function x is classified as standard library function and so its there in the header file but again the same function may also be classified as memory / IO or any other utility function and so its included in the other file as well. Just a semantic help.

mihir83in 12Jun2007 13:54

Re: Basic Question On C
Thats the answer what shabbir said, to put it in simpler words.

A header file is a collection of functions grouped together for a specific task or process, thus all functions in a header file are relative to each other in some context.

Now a function such as exit() or malloc() can have very different applications depending on the needs of a program. For example if you need to use function exit() in your program just to exit then there will be no need of including other 59 functions defined in stdlib.h so they included the exit function in both header files. Process.h is sufficient for dealing with process abortion and ending. while stdlib.h exit function acts the same, but that file would be included when performing some standard i/o operations.

To sum up , they are grouping the functions so that relativity is maintained , and multiple declarations of more generic functions define that user dont have to include all the other unnecessary functions .

I hope that solved your problem, :) Greetings.

naiya 12Jun2007 20:38

Re: Basic Question On C
Shabbir and Mihir
Thank you so much.

All times are GMT +5.5. The time now is 04:05.