Need info on "Safe C library"

E

Erwin Lindemann

Hi group!

I hope this subject is topical here; if not, I apologize
in advance. Context is, some days ago, in
acticle <[email protected]>, somebody posted
a supposedly portable program here. Later, another poster
noticed it didn't compile with one particular compiler, and
it was suggested to report the problem in another group where
said compiler is topical. Well, out of interest what the problem
might be I did just that, and received the following 3-line
response:

----snip----
1) Read the error message.
2) Read the documentation about the safe C library
3) Use another compiler. As I told you in comp.lang.c gcc is the best
----snip----

The error message is
----snip----
lc -ansic -A -O -c ronu.c -o ronu.obj
Error ronu.c: 62 redefinition of 'ConstraintFailed'
Error c:\lcc\include\safelib.h: 3 Previous definition of 'ConstraintFailed' here
Warning ronu.c: 62 inconsistent linkage for 'ConstraintFailed' previously declared at c:\lcc\include\safelib.h 3
2 errors, 1 warning
1 error
----snip----

Obviously, the code in question uses the identifier
"ContraintFailed", which is already declared/defined(?) in
"safelib.h" (which seems to be included by one of the standard
headers). That part was easy.

Now on to (2). What is "the safe C library" and where can I find
information about it. Is it related to N1135?

Chapter 6 in N1135 mentions 2 macros,

__STDC_LIB_EXT1__
The integer constant 200509L, intended to indicate
conformance to this technical report.
(the compiler in question defines __STDC_LIB_EXT1__ empty)

__STDC_WANT_LIB_EXT1__
* Functions, macros, and types declared or defined in N1135
are unavailable if __STDC_WANT_LIB_EXT1__ is defined as a
macro that expands to the integer constant 0.
* Functions, macros, and types declared or defined in N1135
are available if __STDC_WANT_LIB_EXT1__ is defined as a
macro that expands to the integer constant 1 (or other values
as explained in footnote (2)).
* if __STDC_WANT_LIB_EXT1__ is undefined, things are
implementation-defined.
(the compiler in question does not define __STDC_WANT_LIB_EXT1__ itself)

After reading all this, I'm still very confused. What is the correct
way to compile conforming programs with the "safe C library"?

I tried

#define __STDC_WANT_LIB_EXT1__ 0

at the top of the source file; still the same error.

Is there a different document that does reserve "ConstraintFailed"
from usage in the programmer's name space?

Thanks
 
K

Keith Thompson

Erwin Lindemann said:
I hope this subject is topical here; if not, I apologize
in advance. Context is, some days ago, in
acticle <[email protected]>, somebody posted
a supposedly portable program here. Later, another poster
noticed it didn't compile with one particular compiler, and
it was suggested to report the problem in another group where
said compiler is topical. Well, out of interest what the problem
might be I did just that, and received the following 3-line
response:

----snip----
1) Read the error message.
2) Read the documentation about the safe C library
3) Use another compiler. As I told you in comp.lang.c gcc is the best
----snip----

The error message is
----snip----
lc -ansic -A -O -c ronu.c -o ronu.obj
Error ronu.c: 62 redefinition of 'ConstraintFailed'
Error c:\lcc\include\safelib.h: 3 Previous definition of 'ConstraintFailed' here
Warning ronu.c: 62 inconsistent linkage for 'ConstraintFailed' previously declared at c:\lcc\include\safelib.h 3
2 errors, 1 warning
1 error
----snip----

Obviously, the code in question uses the identifier
"ContraintFailed", which is already declared/defined(?) in
"safelib.h" (which seems to be included by one of the standard
headers). That part was easy.

Just to make this easier to talk about, the compiler in question is
apparently lcc-win; the quoted response ("Use another compiler") was
posted to comp.compilers.lcc by jacob navia himself, the maintainer of
lcc-win.

All we can really tell you here is that the C standard does not allow
a conforming implementation to define the identifier ConstraintFailed
in a standard header; it *must* allow a user program to use that
identifier itself. Whether lcc-win's use of this identifier is a
minor bug or a major one is a question I won't try to address, but it
is clearly a violation of the C standard (either C90 or C99).
Compilers are allowed to provide extensions, but they are not allowed
to infringe on the user's name space like this.
Now on to (2). What is "the safe C library" and where can I find
information about it. Is it related to N1135?

It appears not to be related to N1135. I just downloaded that
document; there is no mention of "safelib.h" or "ConstraintFailed".

Perhaps it's something specific to lcc-win. I suggest consulting
lcc-win's own documentation. Perhaps there's a way to disable it.

[...]
After reading all this, I'm still very confused. What is the correct
way to compile conforming programs with the "safe C library"?

I tried

#define __STDC_WANT_LIB_EXT1__ 0

at the top of the source file; still the same error.

Is there a different document that does reserve "ConstraintFailed"
from usage in the programmer's name space?

There certainly should be such a document, but I'm not aware of it.
A Google search for "safelib" and "ConstraintFailed" turned up only
references to this particular problem with lcc-win.

You *could* change your identifier to avoid conflicting with the
implementation's infringing use. You might have to study the
implementation's documentation carefully to find out what other
changes you'll have to make to avoid the implementation's non-standard
quirks.

I think that comp.compilers.lcc is still the best place to discuss
this issue.
 
A

Army1987

Erwin said:
Hi group!

I hope this subject is topical here; if not, I apologize
in advance. Context is, some days ago, in
acticle <[email protected]>, somebody posted
a supposedly portable program here. Later, another poster
noticed it didn't compile with one particular compiler, and
it was suggested to report the problem in another group where
said compiler is topical. Well, out of interest what the problem
might be I did just that, and received the following 3-line
response:

----snip----
1) Read the error message.
2) Read the documentation about the safe C library
3) Use another compiler. As I told you in comp.lang.c gcc is the best
----snip----

The error message is
----snip----
lc -ansic -A -O -c ronu.c -o ronu.obj
Error ronu.c: 62 redefinition of 'ConstraintFailed'
Error c:\lcc\include\safelib.h: 3 Previous definition of 'ConstraintFailed' here
Warning ronu.c: 62 inconsistent linkage for 'ConstraintFailed' previously declared at c:\lcc\include\safelib.h 3
2 errors, 1 warning
1 error
----snip----

Obviously, the code in question uses the identifier
"ContraintFailed", which is already declared/defined(?) in
"safelib.h" (which seems to be included by one of the standard
headers). That part was easy.
[how do I fix that?]
If for some reason you don't want to use another compiler, edit
C:\lcc\include\stdlib.h and move the `#include "safelib.h"` line into the
#ifndef __ANSIC__ONLY__ group. Then, while you're at it, move all other
invasions of user's namespace into that group. In the process, you'll
change your mind about wanting to stick with lcc-win if you care any
little bit about portability.
(And you'll be somewhat puzzled when you see
#define RAND_MAX 0x7FFF
[snip]
#ifndef RAND_MAX
#define RAND_MAX 0x7fff
#endif
in it.)
 

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,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top