c++ standard and file extenstions (.hpp, .H, .hxx)

W

whit

Is anyone aware of language in the standard that guarantees header
files with any extension will be allowed in an #include statement?

The issue is that I'm writing a few "add-on" packages for the R
language. However, the R project rejects any header files that do not
have a .h extension on the basis of compiler portability. i.e. we know
that gcc accepts the .hpp files, but we don't know if other compilers
accept those file extensions.

However, if the standard guarantees that any extensions for header
files can be allowed that is a strong argument for R to change its
policy.

Thanks,
Whit
 
J

James Kanze

There is nothing in the Standard governing the "allowed" or
"prohibited" file name extension AFA textual inclusion is
concerned.

That's not quite true. A conformant implementation is required
to recognize the standard headers in an <...> include (but not
in a "..." include). Also, the standard requires that" The
implementation provides unique mappings for sequences consisting
of one or more nondigits or digits (2.10) followed by a period
(.) and a single nondigit. The first character shall not be a
digit. The implementation may ignore the distinctions of
alphabetical case." (The C standard restricts this to 8
characters before the period. In practice, I don't know of any
C++ implementation which is conform, but all conform to the C
standard.)
The standard headers are all known, and they aren't
necessarily files. It is up to the implementation in what
form it chooses to have those headers. As to your own, you
probably can have anything there, given that the character
sequence between '<' and '>' (or in double quotes) does not
violate the requirements for the preprocessor directive.

The characters between the <...> and the "..." in a return
follow special rules (and the rules aren't necessarily the same
in both cases). What is legal depends on the implementation.
All the standard reuires is that alphanumeric characters are
accepted. In practice, there are probably a few more that are
safe. (I regularly use '/' as a directory separator. But
admittedly, I'm not concerned with portability beyond Unix and
Windows.)
That's up to the compiler. The standard headers, if they are
files, do not have any extensions. The old C headers do, it's
".h", and it's still supported by the C++ Standard, but that's
an *inclusive* requirement, not an *exclusive* one.

In practice, any sequence of alphanumeric characters will work,
at least up to three. What's uncertain is whether case is
distinctive---historically, a lot of C++ headers used .H, which
is confonded with .h on some systems.
There is no such explicit guarantee. It's up to the
implementation.

See above. But in practice, up to three alphanumeric characters
after the . will not cause problems.
 

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

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top