D
David Mathog
One thing that can make porting C code from one
platform to another miserable is #include. In particular,
the need to either place the path to an included file within
the #include statement or to very carefully define the
order in which paths are searched with command line options
on the compiler. Both can cause problems, especially when
dealing with complex software distributions.
It occurs ot me that by extending the C include syntax
slightly it would be possible to clarify matters somewhat.
For instance, consider replacing this:
#include "foo/bar.h"
and this
#include <bar.h> /* same file, but path from compiler */
with this:
#include <bar.h> <foo>
Where the code now says explicitly that the include bar.h is from
a package known as foo. Note, no paths in the include - the
include file is specified by WHAT it is and not by WHERE it is.
To support this the language needs only a minor extension - a
way to map a text file containing the list of packages to
their locations so that the compiler can pull in the right file.
Such a map might look something like:
/* Enable the use of alternative include paths for packages,
for instance on development systems. This would not be
common. */
#if USEALT
#define TOP "/usr/include" /* absolute explicit path */
#else
#define TOP "/usr/altinclude" /* absolute explicit path */
#endif
/*This would be the most common way to associate
a path with a package */
#package foo "/usr/include/foo" /* absolute explict path */
/* or alternatively, a relative explicit path definition, note
substitution within angle brackets, so some other syntax might
be better:
#package foo <TOP/foo>
*/
/* no path means that the path to the package must have been previously
defined or it is an error. */
#package X11
I see several advantages for this extension.
1. If the package doesn't exist the compiler would emit
an error message like:
C compiler error: compiler doesn't know #include package: foo
which tells you immediately that the system either doesn't have foo or
that the map file does not include it. Ideally as packages are
added to a system the default map would be automatically updated, so
that the meaning of this message would be 99.9% of the time that
the package wasn't present on the system. As opposed to:
C compiler error: could not include bar.h
which generally means you have to start spelunking in the code and
looking carefully at the command line to see exactly what's wrong.
Note that if the package exists but the include doesn't, as might happen
for a botched install or a version mismatch, the error message might
be:
C compiler error: found package but not include file
2. A complex package would contain its own map file which
could look something like:
#package X11
#package GL
#define THISPACKAGE "."
#package foo <THISPACKAGE/foo>
#package woo <THISPACKAGE/woo>
where the last three lines define paths to package locations within
the software distribution, and the first two define packages that
are required, but default to the default system map or alternatively
specified compile line map. This would be good because
at least ideally the very first compile could detect the absence of
required packages and stop at that point. Currently on a large
software project one might see hundreds of compiled modules and then
it stops when it can't find some include file. Moreover, one could
just look at this map file to determine if all required packages
are present on the system, and it would be trivial to write a tool
to carry out such a test automatically as part of a "make", for
instance.
3. Allows the unambiguous specification WITHIN THE CODE of the
intended file to be included, even if several packages have include
files with exactly the same name. This specification would survive
any reordering of the directory structure of the code modules.
(Obviously rearranging the include files in their directories would
break it!)
4. The extended syntax is backwards compatible with
existing #include. If the package part was omitted the compiler
would employ the existing #include methods.
Just a thought,
David Mathog
(e-mail address removed)
platform to another miserable is #include. In particular,
the need to either place the path to an included file within
the #include statement or to very carefully define the
order in which paths are searched with command line options
on the compiler. Both can cause problems, especially when
dealing with complex software distributions.
It occurs ot me that by extending the C include syntax
slightly it would be possible to clarify matters somewhat.
For instance, consider replacing this:
#include "foo/bar.h"
and this
#include <bar.h> /* same file, but path from compiler */
with this:
#include <bar.h> <foo>
Where the code now says explicitly that the include bar.h is from
a package known as foo. Note, no paths in the include - the
include file is specified by WHAT it is and not by WHERE it is.
To support this the language needs only a minor extension - a
way to map a text file containing the list of packages to
their locations so that the compiler can pull in the right file.
Such a map might look something like:
/* Enable the use of alternative include paths for packages,
for instance on development systems. This would not be
common. */
#if USEALT
#define TOP "/usr/include" /* absolute explicit path */
#else
#define TOP "/usr/altinclude" /* absolute explicit path */
#endif
/*This would be the most common way to associate
a path with a package */
#package foo "/usr/include/foo" /* absolute explict path */
/* or alternatively, a relative explicit path definition, note
substitution within angle brackets, so some other syntax might
be better:
#package foo <TOP/foo>
*/
/* no path means that the path to the package must have been previously
defined or it is an error. */
#package X11
I see several advantages for this extension.
1. If the package doesn't exist the compiler would emit
an error message like:
C compiler error: compiler doesn't know #include package: foo
which tells you immediately that the system either doesn't have foo or
that the map file does not include it. Ideally as packages are
added to a system the default map would be automatically updated, so
that the meaning of this message would be 99.9% of the time that
the package wasn't present on the system. As opposed to:
C compiler error: could not include bar.h
which generally means you have to start spelunking in the code and
looking carefully at the command line to see exactly what's wrong.
Note that if the package exists but the include doesn't, as might happen
for a botched install or a version mismatch, the error message might
be:
C compiler error: found package but not include file
2. A complex package would contain its own map file which
could look something like:
#package X11
#package GL
#define THISPACKAGE "."
#package foo <THISPACKAGE/foo>
#package woo <THISPACKAGE/woo>
where the last three lines define paths to package locations within
the software distribution, and the first two define packages that
are required, but default to the default system map or alternatively
specified compile line map. This would be good because
at least ideally the very first compile could detect the absence of
required packages and stop at that point. Currently on a large
software project one might see hundreds of compiled modules and then
it stops when it can't find some include file. Moreover, one could
just look at this map file to determine if all required packages
are present on the system, and it would be trivial to write a tool
to carry out such a test automatically as part of a "make", for
instance.
3. Allows the unambiguous specification WITHIN THE CODE of the
intended file to be included, even if several packages have include
files with exactly the same name. This specification would survive
any reordering of the directory structure of the code modules.
(Obviously rearranging the include files in their directories would
break it!)
4. The extended syntax is backwards compatible with
existing #include. If the package part was omitted the compiler
would employ the existing #include methods.
Just a thought,
David Mathog
(e-mail address removed)