Token pasting in #include directive
Chris Torek
chris at mimsy.umd.edu
Tue Nov 28 18:03:53 AEST 1989
>In article <18672 at watdragon.waterloo.edu> afscian at violet.waterloo.edu
>(Anthony Scian) writes:
>>What about the library prototypes that are coded "int foo( int x, int y )"
>>when they should be "int foo( int __x, int __y )"?
In article <970 at sdrc.UUCP> scjones at sdrc.UUCP (Larry Jones) writes:
>Eh? Why is the second any more correct than the first? Since
>the argument names in a prototype only have prototype scope, they
>can't conflict with any other names in the program and therefor
>do not need leading underscores.
The following is (apparently---anyone who can supply text proving otherwise
is welcome to follow up) legal:
#define x point.xpart
#define y point.ypart
#include <math.h>
Thus, if <math.h> includes the line
double pow(double x, double y);
the compiler will attempt to parse the expansion
double pow(double point.xpart, double point.ypart);
which will give a syntax error.
However, the following is (apparently) illegal:
#define _x point.x /* this has file scope and is thus illegal */
#define _y point.y /* (at least, at this point) */
#include <math.h>
hence <math.h> *could* include the line
double pow(double _x, double _y);
Names such as `_a' (apparently) cannot exist with file scope% at the
time of a `#include some_standard_header', and names such as `_A'
(underscore followed by an uppercase letter or a second underscore)
are completely off-limits to users.
-----
% Maybe they can, provided they are not `#define' symbols, since
static double _x() {
return 3.14159265358979323/2.718281828459045235);
}
#include <math.h>
seems unlikely to cause trouble. But `#define x some,long,expr'
is otherwise quite all right, but will discombobulate prototypes.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at cs.umd.edu Path: uunet!mimsy!chris
More information about the Comp.std.c
mailing list