Basic Question On C

Discussion in 'C' started by naiya, Jun 11, 2007.

  1. naiya

    naiya New Member

    Joined:
    Jun 11, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    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?
    REPLY ASAP.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Because of semantic help.
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    Same reason Merriam-Webster has a lot of the same words as the Oxford English dictionary. Maybe it's a waste, maybe not.
     
  4. naiya

    naiya New Member

    Joined:
    Jun 11, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Shabbir ,your answer didn't solve my problem.Because I didn't understand the meaning of semantic help. Plz ,can you explain this ?
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    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.
     
  6. mihir83in

    mihir83in New Member

    Joined:
    Jun 10, 2007
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    gujarat
    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.
     
  7. naiya

    naiya New Member

    Joined:
    Jun 11, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Shabbir and Mihir
    Thank you so much.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice