🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Ronald F. Guilmette Sun, 15 Nov 1992 23:52
Header files and "hidden built-in type hacks".
#852
Author: Ronald F. Guilmette
Date: Sun, 15 Nov 1992 23:52
71 lines
4061 bytes
Submitted-by: rfg@netcom.com (Ronald F. Guilmette)

As the regular readers of comp.std.c are probably aware, there is a
rather strange set of (seemingly conflicting) requirements with regard
to the declaration of certain implementation-defined primitive data types
and certain header files.

The most commonly cited example is the type `va_list' and the <stdio.h>
header file.

Certain of the functions which must be declared (preferably with prototypes)
in the <stdio.h> file (e.g. vprintf) are defined (by the ANSI C standard) to
take arguments of type `va_list'.  So if these function are declared (using
prototypes) within <stdio.h> it seems (at first glance) that the implementa-
tion must arrange to have the type `va_list' be declared whenever <stdio.h>
is included into any compilation unit.

But careful implementors know that if `va_list' is declared whever <stdio.h>
is included, this will cause an small but unnecessary (and possibly illegal)
pollution of the user's namespace.  Thus, careful implementors always make
use of some *other* symbol (e.g. __va_list or __builtin_va_list) as the
formal type given for the "va_list" type parameters in the prototyped
function declarations in <stdio.h>.

I have two questions about this practice, and two follow-up observations.

My first question is simply this.  Is the practice of avoiding definition
of a va_list type in <stdio.h> strictly required by the ANSI C standard?
My (naive?) believe is that this practice *is* required in order to avoid
non-standard pollution of the user's namespace.

My second question assumes that the answer to the first question is "yes".

My second question is also a simple one.  In what other cases are such
"hidden built-in type hacks" required as a result of other requirements
in the ANSI C standard (or in POSIX 1003.1-1990)?

My first observation is that it appears that another "hidden built-in type
hack" (similar to the one for va_list and <stdio.h>) is also required in
the case of the <time.h> file, where the ANSI C standard requires that the
second formal parameter for the `strftime' function have type `size_t'
even though section 4.12.1 (describing <time.h>) does not seem to permit
<time.h> to define the size_t type.

My second observation is that it appears that another such case arises
for those who wish to implement strict conformance with POSIX 1003.1-1990.
Sepcifically, while POSIX 1003.1-1990 seems to require that <sys/types.h>
be included prior to <sys/stat.h>, certain of the things which must be
declared within <sys/types.h> (under the rules of POSIX 1003.1-1990) must
have type `time_t' even though neither <sys/stat.h> nor <sys/types.h> are
required (by POSIX) to define such a type.

(Footnote:  I know that POSIX 1003.1-1990 explicitly permits <sys/types.h>
to contain additional type declarations above and beyond those which are
minimally required to appear there, but there are some implementors who
are fanatics about the avoidance of arbitrary implementation-dependent
bits of namespace pollution, and I can well imagine that such implementors
would wish to use one of these "hidden built-in type hacks" for the
`time_t' type in <sys/stat.h>.  Now I just want to now if the rules permit
them to do that, and if they should be encouraged to do it.)

-- 

// Ron ("Loose Cannon") Guilmette
// uucp: ...uunet!lupine!segfault!rfg
// New new motto:  Quality control is a state of mind.
//   misc.forsale.computers ad, circa 2007:
//       Used Cray wrist watch for sale; 25 bucks or best offer.


Volume-Number: Volume 29, Number 70
Re: Header files and "hidden built-in type hacks".
#854
Author: Steve Clamage
Date: Wed, 18 Nov 1992 06:16
34 lines
2033 bytes
Submitted-by: steve@taumet.com (Steve Clamage)

rfg@netcom.com (Ronald F. Guilmette) writes:
>My first question is simply this.  Is the practice of avoiding definition
>of a va_list type in <stdio.h> strictly required by the ANSI C standard?
>My (naive?) believe is that this practice *is* required in order to avoid
>non-standard pollution of the user's namespace.

ANSI section 4.1.2.1 in conjunction with 4.8 and 4.9 makes it very clear
that <stdio.h> cannot define the identifier "va_list".  It is legal for
a user program to include <stdio.h> without including <stdarg.h>.  If
<stdarg.h> is not included, the identifier va_list is not reserved.
Hence hacks like __va_list which are a conforming way around the problem.

>My second question is also a simple one.  In what other cases are such
>"hidden built-in type hacks" required as a result of other requirements
>in the ANSI C standard (or in POSIX 1003.1-1990)?

I can't speak to the POSIX question.  Any identifier which is not
reserved according to 4.1.2.1 and which is implicitly referenced but
not defined by a Standard C header must have some sort of work-around.
(Only those identifiers not otherwise reserved may be defined in a
conforming Standard C header.)

Some types, like size_t, must be defined in more than one header.
This means that some workaround is needed for these types as well
to avoid multiple definitions.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com
Vice Chair, ANSI C++ Committee, X3J16


Volume-Number: Volume 29, Number 72
Re: Header files and "hidden built-in type hacks".
#855
Author: Norman Diamond
Date: Wed, 18 Nov 1992 06:20
41 lines
2546 bytes
Submitted-by: diamond@jit345.bad.jit.dec.com (Norman Diamond)

In article <1e6nslINN4rd@ftp.UU.NET> rfg@netcom.com (Ronald F. Guilmette) writes:
>Certain of the functions which must be declared (preferably with prototypes)
>in the <stdio.h> file (e.g. vprintf) are defined (by the ANSI C standard) to
>take arguments of type `va_list'.

If a user's program declares printf instead of doing #include <stdio.h> then
the user's program must include a prototype with ellipsis ", ...".
If you're talking about the internals of the implementation's <stdio.h> then
the implementation is allowed to encode the declarations however it likes,
not necessarily encoded in the C language, not necessarily using prototypes
-- the implementation can choose any method that works for itself.

>But careful implementors know that if `va_list' is declared whever <stdio.h>
>is included, this will cause an small but unnecessary (and possibly illegal)
>pollution of the user's namespace.
>My first question is simply this.  Is the practice of avoiding definition
>of a va_list type in <stdio.h> strictly required by the ANSI C standard?

Yes.  s/possibly//  And carelessness yields non-conforming implementations.

>In what other cases are such "hidden built-in type hacks" required as a result
>of other requirements in the ANSI C standard (or in POSIX 1003.1-1990)?

It's probably easiest to encode hidden built-in type hacks for EVERYTHING and
avoid exactly this worry (assuming that you're an implementor).

[Examples deleted:  size_t in <time.h> and time_t in <sys/stat.h>]

ANSI C section 4.12.1, page 171 line 12, says that <time.h> declares size_t.
I don't have the POSIX standard.

--
Norman Diamond       diamond@jit081.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
"It's been a lovely recession."

[ Note followup-to: line, please.  Thanks -- mod ]

Volume-Number: Volume 29, Number 73
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads