C++0x standalone standard library implementation requirements?

This is a discussion on C++0x standalone standard library implementation requirements? within the C++ Programming forums, part of the General Programming Boards category; I vaguely remember that there is a special spec in the C standard for standalone(no OS intervention) implementations of libc. ...

  1. #1
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587

    C++ freestanding implementation requirements?

    I vaguely remember that there is a special spec in the C standard for standalone(no OS intervention) implementations of libc. I have two questions, 1) What chapter/section is this in? 2) Is there a C++/STL equivalent?

    I'm considering doing a rewrite of my, so far, insignificant kernel in C++, if most of the relevant part of the STL is required for standalone implementations.

    EDIT: I just remembered, it's called "freestanding," and it's covered in 5.1.2.1. Now that I know the official name I can do some research in the C++ standards.
    Last edited by User Name:; 01-12-2011 at 06:15 AM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,643
    Both the C and C++ standards specify a "hosted" and a "freestanding" implementation. "Hosted" essentially means "supports everything in the standard". "Freestanding" means "at least a specified subset of the library". Program startup and termination (i.e. what happens before and after main(), if supported) are implementation defined for a freestanding environment.

    In the 1999 C standard, a conforming freestanding implementation is limited to not using complex types (as in complex numbers), and is required to support (as a minimum) standard headers <float.h>, <iso646.h>, <limits.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, and <stdint.h>. The relevant clauses are in Section 4 "Conformance", para 6 and there is more said in Section 5.1.2.1 "Freestanding environment".

    In the 1998 C++ standard, the minimum subset of the library that a freestanding is in the headers <cstddef>, <limits>, <cstdlib>, <new>, <typeinfo>, <exception>, and <cstdarg>. <cstddef> must declare, at minimum, abort(), atexit(), and exit(). The relevant section in the C++ standard is 17.4.1.3 "Freestanding implementations".

    In both standards, it is implementation defined whether or not other standard headers are supported in a freestanding implementation. In other words, freestanding implementations are not limited to just the minimum.

    I'm not sure offhand if the proposed C++0x changes the definition of a freestanding implementation, or if the sections are named or numbered differently.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    15
    My version of the C++0x draft says the freestanding subset(17.6.1.3) must consist of:

    • <cstddef>
    • <limits>
    • <cstdlib>
    • <new>
    • <typeinfo>
    • <exception>
    • <initializer_list>
    • <cstdarg>
    • <type_traits>
    • <thread>


    The supplied version of the header <cstdlib> shall declare at least the functions abort, atexit, at_ quick_exit, exit, and quick_exit (18.5).

    The supplied version of the header <thread> shall meet the same requirements as for a hosted implementation or including it shall have no effect. The other headers listed in this table shall meet the same requirements as for a hosted implementation.

  4. #4
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    Thanks. That's disappointing. I was hoping they would require the parts of the STL that don't need dynamic allocation.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,643
    There is nothing preventing a freestanding implementation from implementing more than the minimum.

    Simply document the requirements of your "kernel" to be a minimal freestanding implementation plus whatever other headers you need.

    If your "kernel" is "insignificant", it is quite possible the amount of the STL needed would be quite small (eg a subset of the algorithms). A lot of the STL is actually quite simple, so you might be able to implement a usable equivalent for your kernel. That would require some more work, but would allow you to target a minimal freestanding implementation.

    Incidentally, the logic of these things normally goes the other way. Someone implementing a compiler for a computing platform decides whether to make it hosted or freestanding. Then you, as an end-user developing your "kernel", decide which computing platforms to target.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  6. #6
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    I know what you mean. All I really need, for now, is bitset for my heap allocator. I like to keep things really neat, and well designed. I'd like to avoid the work necessary to implement a well designed subset of libc++. That's basically my only reason for not just making a simple bitset for myself. I guess I'll just go ahead and do it anyway.

    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to override standard printf defined in gcc library
    By RahulJain83 in forum C Programming
    Replies: 7
    Last Post: 10-27-2009, 10:23 PM
  2. C Standard Library
    By JoshG in forum C Programming
    Replies: 2
    Last Post: 07-17-2002, 10:09 AM
  3. Links to learn standard C library functions...
    By Nutshell in forum C Programming
    Replies: 8
    Last Post: 02-01-2002, 12:41 AM
  4. Source code of the standard library functions...
    By Nutshell in forum C Programming
    Replies: 2
    Last Post: 01-21-2002, 12:35 PM
  5. C standard library
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 12:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21