Page 2 of 2 First 12
  • Jump to page:
    #16
  1. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,075
    Rep Power
    1802
    Originally Posted by bdb
    Anyway, parts of the library that have to deal with the Host Operating System (for allocating memory or opening streams for instance) cannot be written in "pure standard conforming (freestanding) C"
    If indeed the target has a host operating system. If in mapping a library to some specific OS you may indeed need to make OS specific calls (primarily for low-level I/O and memory allocation) and those functions may be written in any language, including C. In some cases such as MS-DOS where DOS or BIOS calls are made through software interrupts there is indeed no C language mechanism to support that directly.

    However the use of OS specific code does not render such code as either impure or non-compliant - merely non-portable.

    I work in embedded systems and have in the past ported libraries such as Newlib to bare-metal targets and targets using a RTOS kernel, and in doing so have never needed assembler code. The only OS calls necessary were for mutual-exclusion for heap operations, and even the RTOS mutex code was written in C.
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    59
    Rep Power
    3
    Thanks for pointing out the Wikipedia article on Include guard. Now I understand it appears in the include file in order to make the definition of a data structure occur exactly one time. I see it works the same way as a first pass flag in a function, but in the context of compiling rather than that of running.
    Last edited by EEmaestro; September 5th, 2012 at 11:34 AM.
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    San Francisco Bay
    Posts
    1,939
    Rep Power
    1313
    Originally Posted by Scorpions4ever
    With that said, here's a libc that is used by OpenBSD and is freely available on the web:
    http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/
    ...and here's glibc (the GNU project's C standard library): http://sourceware.org/git/?p=glibc.git;a=tree
  6. #19
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    12
    Rep Power
    0

    Back!


    Hello! I had a new stream of related questions, so I thought I'd pop back. My last question however is still unanswered, so I'll ask again - What does the macro GRANDFATHER_H mean/imply/contain? The #define directive I understand in the context of replacement texts, but in the case of header files its all muddy to me.
  8. #20
  9. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,075
    Rep Power
    1802
    Originally Posted by st_crab
    My last question however is still unanswered, so I'll ask again
    So perhaps you should have started a new thread rather than tacking on an unrelated question mid thread. That assumes that everyone will read the entire thread rather than just answering the original question.

    Originally Posted by st_crab
    What does the macro GRANDFATHER_H mean/imply/contain? The #define directive I understand in the context of replacement texts, but in the case of header files its all muddy to me.
    There is nothing special about header files - they are source code like any other - the compiler does not process them any differently than any other code.

    In the case of the include guard idiom...

    Code:
    #if !defined FILENAME_INCLUDE
    #define FILENAME_INCLUDE
    
    ....
    
    #endif
    ... a macro can be defined or undefined, and if it is defined it may also have a value - but it need not. So here we are not using the "value" of FILENAME_INCLUDE we are simply using its boolean state of defined or undefined; its value is irrelevant since it is not used as text replacement, and in this case indeed it has no value.
  10. #21
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    8
    Rep Power
    0
    Originally Posted by st_crab
    Now, I opened stdio.h (I'm using DevC++. I browse to the "include" directory to explore C's header files), to think that I'd find the full definitions of all the standard in/out functions, but all I find are just declarations! Where do the full definitions lie?
    No one has mentioned yet to look at the man pages. Many pages online offer these man pages. Here is an example:

    www unix dot com / man-page / all / 3head / stdio.h /

    The manpage is usually much better for documentation purposes than looking at the header file.
  12. #22
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    12
    Rep Power
    0
    Originally Posted by clifford
    So perhaps you should have started a new thread rather than tacking on an unrelated question mid thread. That assumes that everyone will read the entire thread rather than just answering the original question.
    I apologize, I didn't think about it that way. The deed is done, though!



    Originally Posted by clifford
    There is nothing special about header files - they are source code like any other - the compiler does not process them any differently than any other code.

    In the case of the include guard idiom...

    Code:
    #if !defined FILENAME_INCLUDE
    #define FILENAME_INCLUDE
    
    ....
    
    #endif
    ... a macro can be defined or undefined, and if it is defined it may also have a value - but it need not. So here we are not using the "value" of FILENAME_INCLUDE we are simply using its boolean state of defined or undefined; its value is irrelevant since it is not used as text replacement, and in this case indeed it has no value.
    I see, so each macro also has a boolean state associated with it? Ok, that's good, but how does the preprocessor know, in this case for example, that the lines after "#define FILENAME_INCLUDE" have to be included, when usually a define directive causes the preprocessor to only read the following text in the same line only?

    Also, in light of this new info I'd like to ask about the #include directive - it basically throws all the code of the (mentioned) header file right there at the spot, AND it creates a (value-less") macro by the name of HEADERFILENAME_H?
  14. #23
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    8
    Rep Power
    0
    Originally Posted by st_crab
    Also, in light of this new info I'd like to ask about the #include directive - it basically throws all the code of the (mentioned) header file right there at the spot, AND it creates a (value-less") macro by the name of HEADERFILENAME_H?
    The sequence

    C Code:
    #ifndef MY_HEADER_H
    #define MY_HEADER_H
     
    // ... some code
     
    #endif

    can be thought of operating as follows: the compiler goes to the first line and if MY_HEADER_H is already defined, it stops. If it is *not* already defined, then it procedes to line 2, where MY_HEADER_H is defined. Then all of the code is compiled.

    In other words, when you #include foo.h, there is no rule that says a symbol called FOO_H will be made. You have to do it yourself (via the #define directive in line 2).
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo