standard libraries

J

Jim Showalter

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

jacob navia

Jim said:
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
 
R

Richard Heathfield

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.
 
P

pete

Jim said:
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>
 
P

pete

Richard said:
Jim Showalter said:


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.
 
J

Jim Showalter

jacob said:
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.
 
K

Keith Thompson

Jim Showalter said:
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.
 
R

Richard Heathfield

pete said:
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?
 
M

Malcolm

Jim Showalter said:
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.
 
J

jacob navia

Jim said:
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
 
R

Richard Heathfield

pete said:
Richard said:
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.
 
T

those who know me have no need of my name

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].
 
J

jacob navia

those said:
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
 
R

Richard Heathfield

jacob navia said:

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.

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.
 
J

jacob navia

Richard Heathfield a écrit :
jacob navia said:




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.
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?
 
R

Richard Heathfield

jacob navia said:
Richard Heathfield a écrit :
jacob navia said:




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, 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.
 
M

Michael Mair

jacob said:
Richard Heathfield a écrit :
jacob navia said:


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
 
J

jacob navia

Michael said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top