standard libraries

Discussion in 'C Programming' started by Jim Showalter, Sep 16, 2006.

  1. Does a hosted implementation require any particular libraries in order to be
    considered a standard C compiler?
    --
    _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
    _/ Everything should be made as simple as possible, but not simpler.
    _/ -- Albert Einstein
    _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
     
    Jim Showalter, Sep 16, 2006
    #1
    1. Advertising

  2. Jim Showalter

    jacob navia Guest

    Jim Showalter wrote:
    > Does a hosted implementation require any particular libraries in order to be
    > considered a standard C compiler?


    I suppose that the standard C library (at least) should be present.
    In any case a compiler without any library is not very useful...

    jacob
     
    jacob navia, Sep 16, 2006
    #2
    1. Advertising

  3. Jim Showalter said:

    > Does a hosted implementation require any particular libraries in order to
    > be considered a standard C compiler?


    A hosted implementation must provide all the standard library functions, but
    the Standard does not say in what form they must be provided.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Sep 16, 2006
    #3
  4. Jim Showalter

    pete Guest

    Jim Showalter wrote:
    >
    > Does a hosted implementation require
    > any particular libraries in order to be
    > considered a standard C compiler?


    Yes.

    C89, hosted:
    <assert.h> <locale.h> <stddef.h>
    <ctype.h> <math.h> <stdio.h>
    <errno.h> <setjmp.h> <stdlib.h>
    <float.h> <signal.h> <string.h>
    <limits.h> <stdarg.h> <time.h>

    C89, freestanding:
    <float.h> <limits.h> <stdarg.h>
    <stddef.h>

    C99, hosted:
    <assert.h> <complex.h> <ctype.h>
    <errno.h> <fenv.h> <float.h>
    <inttypes.h> <iso646.h> <limits.h>
    <locale.h> <math.h> <setjmp.h>
    <signal.h> <stdarg.h> <stdbool.h>
    <stddef.h> <stdint.h> <stdio.h>
    <stdlib.h> <string.h> <tgmath.h>
    <time.h> <wchar.h> <wctype.h>

    C99, freestanding
    <float.h> <iso646.h> <limits.h>
    <stdarg.h> <stdbool.h> <stddef.h>
    <stdint.h>

    --
    pete
     
    pete, Sep 16, 2006
    #4
  5. Jim Showalter

    pete Guest

    Richard Heathfield wrote:
    >
    > Jim Showalter said:
    >
    > > Does a hosted implementation require
    > > any particular libraries in order to
    > > be considered a standard C compiler?

    >
    > A hosted implementation must provide
    > all the standard library functions, but
    > the Standard does not say in what form they must be provided.


    Yes.

    This directive in a C file: #include <float.h>
    only means that the compiler has to compile the C file
    as though float.h was pasted in there.
    If that can be done without a float.h file being present,
    then there doesn't need to be a float.h file
    in the hosted implementation.

    --
    pete
     
    pete, Sep 16, 2006
    #5
  6. jacob navia wrote:
    >
    > I suppose that the standard C library (at least) should be present.
    > In any case a compiler without any library is not very useful...
    >
    > jacob


    That's what I thought, too. But I've installed the latest versions of MinGW
    along with gcc-core, and cannot find even a mention of libc or glibc.

    --
    _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
    _/ Everything should be made as simple as possible, but not simpler.
    _/ -- Albert Einstein
    _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
     
    Jim Showalter, Sep 16, 2006
    #6
  7. Jim Showalter <> writes:
    > jacob navia wrote:
    >> I suppose that the standard C library (at least) should be present.
    >> In any case a compiler without any library is not very useful...

    >
    > That's what I thought, too. But I've installed the latest versions
    > of MinGW along with gcc-core, and cannot find even a mention of libc
    > or glibc.


    The standard says nothing about "libc" or "glibc". As long as a
    program that includes standard headers and calls standard library
    functions works as specified in the standard, it doesn't matter how
    the implementation does it.

    <OT>gcc typically uses whatever runtime library is provided by the
    underlying operating system. I don't know what MinGW does.</OT>

    If you're curious about the details of how your implementation
    provides the standard library headers and fucntions, either check your
    implementation's documentation or ask in a system-specific newsgroup.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Sep 16, 2006
    #7
  8. pete said:

    > Jim Showalter wrote:
    >>
    >> Does a hosted implementation require
    >> any particular libraries in order to be
    >> considered a standard C compiler?

    >
    > Yes.
    >
    > C89, hosted:
    > <assert.h> <locale.h> <stddef.h>


    [etc]

    Those are not libraries. They're headers.

    <snip>

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Sep 17, 2006
    #8
  9. pete said:

    > Richard Heathfield wrote:
    >>
    >> Jim Showalter said:
    >>
    >> > Does a hosted implementation require
    >> > any particular libraries in order to
    >> > be considered a standard C compiler?

    >>
    >> A hosted implementation must provide
    >> all the standard library functions, but
    >> the Standard does not say in what form they must be provided.

    >
    > Yes.
    >
    > This directive in a C file: #include <float.h>
    > only means that the compiler has to compile the C file
    > as though float.h was pasted in there.
    > If that can be done without a float.h file being present,
    > then there doesn't need to be a float.h file
    > in the hosted implementation.


    What has <float.h> to do with libraries?

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Sep 17, 2006
    #9
  10. Jim Showalter

    Malcolm Guest

    "Jim Showalter" <> wrote
    >
    > Does a hosted implementation require any particular libraries in order to
    > be
    > considered a standard C compiler?
    >

    Yes. the standard library.
    The problem is that most hosted implementations run on computers with
    graphical user interfaces, and there are no standard library functions for
    communicating with a GUI. Some evil systems also take away streams such as
    stderr and stdout, which makes life very difficult.
    --
    www.personal.leeds.ac.uk/~bgy1mm
    freeware games to download.
     
    Malcolm, Sep 17, 2006
    #10
  11. Jim Showalter

    pete Guest

    Richard Heathfield wrote:
    >
    > pete said:
    >
    > > Jim Showalter wrote:
    > >>
    > >> Does a hosted implementation require
    > >> any particular libraries in order to be
    > >> considered a standard C compiler?

    > >
    > > Yes.
    > >
    > > C89, hosted:
    > > <assert.h> <locale.h> <stddef.h>

    >
    > [etc]
    >
    > Those are not libraries. They're headers.
    >
    > <snip>


    Parts of the standard library,
    are sometimes refered to as "libraries",
    such as "the math library",
    which is mentioned in the FAQ.

    http://c-faq.com/fp/libm.html

    --
    pete
     
    pete, Sep 17, 2006
    #11
  12. Jim Showalter

    jacob navia Guest

    Jim Showalter wrote:
    > jacob navia wrote:
    >
    >>I suppose that the standard C library (at least) should be present.
    >>In any case a compiler without any library is not very useful...
    >>
    >>jacob

    >
    >
    > That's what I thought, too. But I've installed the latest versions of MinGW
    > along with gcc-core, and cannot find even a mention of libc or glibc.
    >


    mingw doesn't have an own version of the standard C
    Library and uses the implementation provided with the
    operating system: crtdll.dll.

    This rather ancient implementation will provide you with
    C89 semantics with a compiler that can possible emit
    C99 code, so take care as not to ask for anything
    recent what standards is concerned.

    At the same time, even if the compiler accepts and emits
    code for long doubles, mingw doesn't have any library support
    for long doubles so better not use them.

    The same with long longs, since the printf version of crtdll.dll
    doesn't understand any long long semantics. Maybe it understands
    long long ll;
    printf("%I64d\n",ll);

    but I am not sure about it.

    Another possibility is that you make mingw link with the
    C library of the microsoft compiler system, but I do
    not know how to do that or if it is fair to do this (use
    Microsoft's libraries without buying a copy of the
    Microsoft compiler); See your lawyer for additional
    information :)

    jacob
     
    jacob navia, Sep 17, 2006
    #12
  13. pete said:

    > Richard Heathfield wrote:
    >>
    >> pete said:
    >>
    >> > Jim Showalter wrote:
    >> >>
    >> >> Does a hosted implementation require
    >> >> any particular libraries in order to be
    >> >> considered a standard C compiler?
    >> >
    >> > Yes.
    >> >
    >> > C89, hosted:
    >> > <assert.h> <locale.h> <stddef.h>

    >>
    >> [etc]
    >>
    >> Those are not libraries. They're headers.
    >>
    >> <snip>

    >
    > Parts of the standard library,
    > are sometimes refered to as "libraries",


    Erroneously.

    > such as "the math library",
    > which is mentioned in the FAQ.
    >
    > http://c-faq.com/fp/libm.html


    If you read it more carefully, you'll see that the question addresses the
    /difference/ between headers and libraries. When it's talking about "the
    math library", it is talking about "actually linking with the math
    *library*", not "linking with the <math.h> header". You don't link with
    headers.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Sep 17, 2006
    #13
  14. in comp.lang.c i read:

    [re: platform provided standard c library]
    >This rather ancient implementation will provide you with
    >C89 semantics with a compiler that can possible emit
    >C99 code, so take care as not to ask for anything
    >recent what standards is concerned.


    eh? decoder ring needed.

    >At the same time, even if the compiler accepts and emits
    >code for long doubles, mingw doesn't have any library support
    >for long doubles so better not use them.


    that would be sad then, since long double has been part of the language for
    a long time [c89 3.1.2.5].

    --
    a signature
     
    those who know me have no need of my name, Oct 2, 2006
    #14
  15. Jim Showalter

    jacob navia Guest

    those who know me have no need of my name wrote:
    > in comp.lang.c i read:
    >
    > [re: platform provided standard c library]
    >
    >>This rather ancient implementation will provide you with
    >>C89 semantics with a compiler that can possible emit
    >>C99 code, so take care as not to ask for anything
    >>recent what standards is concerned.

    >
    >
    > eh? decoder ring needed.
    >

    This means that the printf provided by crtdll.dll is strictly
    C89 and doesn't provide any way of printing either
    long doubles, long longs or any normal printf directives.

    OK?

    >
    >>At the same time, even if the compiler accepts and emits
    >>code for long doubles, mingw doesn't have any library support
    >>for long doubles so better not use them.

    >
    >
    > that would be sad then, since long double has been part of the language for
    > a long time [c89 3.1.2.5].
    >


    Yes, but microsoft implemented long double as a
    synonym for double. Since gcc has real long doubles
    the library CRTDLL.DLL does NOT follow and you are stuck
     
    jacob navia, Oct 2, 2006
    #15
  16. jacob navia said:

    <snip>

    > This means that the printf provided by crtdll.dll is strictly
    > C89 and doesn't provide any way of printing either
    > long doubles, long longs or any normal printf directives.


    That's a contradiction. If it's strictly C89, it will provide a way to print
    long doubles.

    <snip>

    > Yes, but microsoft implemented long double as a
    > synonym for double.


    Only in some of their implementations. I have a couple of Microsoft
    compilers with 80-bit long doubles, compared to just 64 bits for double.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Oct 2, 2006
    #16
  17. Jim Showalter

    jacob navia Guest

    Richard Heathfield a écrit :
    > jacob navia said:
    >
    > <snip>
    >
    >>This means that the printf provided by crtdll.dll is strictly
    >>C89 and doesn't provide any way of printing either
    >>long doubles, long longs or any normal printf directives.

    >
    >
    > That's a contradiction. If it's strictly C89, it will provide a way to print
    > long doubles.
    >
    > <snip>



    #include <stdio.h>
    int main(int argc, char *argv[])
    {
    long double d = 1e600L;

    printf("%Le\n",d);
    return 0;
    }

    This will FAIL under mingw.

    I posted you this message in another thread but you continue
    to post nonsense.

    >
    >
    >>Yes, but microsoft implemented long double as a
    >>synonym for double.

    >
    >
    > Only in some of their implementations. I have a couple of Microsoft
    > compilers with 80-bit long doubles, compared to just 64 bits for double.
    >


    Yes, very ancient implementations have real long doubles. Modern ones
    have not.

    Why confuse people? It is your hobby or what?
     
    jacob navia, Oct 2, 2006
    #17
  18. jacob navia said:

    > Richard Heathfield a écrit :
    >> jacob navia said:
    >>
    >> <snip>
    >>
    >>>This means that the printf provided by crtdll.dll is strictly
    >>>C89 and doesn't provide any way of printing either
    >>>long doubles, long longs or any normal printf directives.

    >>
    >>
    >> That's a contradiction. If it's strictly C89, it will provide a way to
    >> print long doubles.
    >>
    >> <snip>

    >
    >
    > #include <stdio.h>
    > int main(int argc, char *argv[])
    > {
    > long double d = 1e600L;
    >
    > printf("%Le\n",d);
    > return 0;
    > }
    >
    > This will FAIL under mingw.


    You claimed:
    (a) mingw uses the C runtime library provided in crtdll.dll
    (b) the printf provided by that library is strictly C89
    (c) the printf provided by that library doesn't provide a way to print long
    doubles

    It's possible that my C89 draft is wrong, I suppose, but anyway it says:

    an optional L specifying that a following e , E , f , g , or G
    conversion specifier applies to a long double argument.

    Was that removed from the Standard at the last moment?

    If so, then all that you have said makes sense. But if not, then I don't
    understand what point you are making, as you appear to be contradicting
    yourself.


    >>>Yes, but microsoft implemented long double as a
    >>>synonym for double.

    >>
    >>
    >> Only in some of their implementations. I have a couple of Microsoft
    >> compilers with 80-bit long doubles, compared to just 64 bits for double.
    >>

    >
    > Yes, very ancient implementations have real long doubles. Modern ones
    > have not.
    >
    > Why confuse people? It is your hobby or what?


    I am sorry if you find the facts confusing.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Oct 2, 2006
    #18
  19. Jim Showalter

    Michael Mair Guest

    jacob navia wrote:
    > Richard Heathfield a écrit :
    >> jacob navia said:
    >> <snip>
    >>
    >>> This means that the printf provided by crtdll.dll is strictly
    >>> C89 and doesn't provide any way of printing either
    >>> long doubles, long longs or any normal printf directives.

    >>
    >> That's a contradiction. If it's strictly C89, it will provide a way to
    >> print long doubles.
    >>
    >> <snip>

    >
    > #include <stdio.h>
    > int main(int argc, char *argv[])
    > {
    > long double d = 1e600L;
    >
    > printf("%Le\n",d);
    > return 0;
    > }
    >
    > This will FAIL under mingw.
    >
    > I posted you this message in another thread but you continue
    > to post nonsense.


    Yes, but the problem is that mingw plus MS libs is _not_ a
    conforming implementation.
    long doubles, doubles, and floats can have exactly the same size
    and representation.
    The above code relies on implementation limits rather than
    guaranteed standard limits (LDBL_MAX is guaranteed to be at least
    1E+37).
    The obvious fix is to not use mingw in this combination as it is
    broken (or keep in mind that it is broken w.r.t. long double I/O).


    Cheers
    Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
     
    Michael Mair, Oct 2, 2006
    #19
  20. Jim Showalter

    jacob navia Guest

    Michael Mair wrote:
    > Yes, but the problem is that mingw plus MS libs is _not_ a
    > conforming implementation.
    > long doubles, doubles, and floats can have exactly the same size
    > and representation.
    > The above code relies on implementation limits rather than
    > guaranteed standard limits (LDBL_MAX is guaranteed to be at least
    > 1E+37).
    > The obvious fix is to not use mingw in this combination as it is
    > broken (or keep in mind that it is broken w.r.t. long double I/O).
    >


    This is exactly what I wanted to convey. Same problems appear with
    long long.
     
    jacob navia, Oct 2, 2006
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kir
    Replies:
    1
    Views:
    368
    Scott Yanoff
    Sep 16, 2003
  2. Greg P.
    Replies:
    3
    Views:
    472
    Greg P.
    Aug 28, 2003
  3. fabio de francesco
    Replies:
    3
    Views:
    427
  4. Karsten Wutzke
    Replies:
    21
    Views:
    946
    Roedy Green
    Jun 29, 2007
  5. Sriram Srinivasan
    Replies:
    13
    Views:
    596
    Benjamin Kaplan
    Nov 12, 2009
Loading...

Share This Page