Article View: comp.std.c
Article #1023Re: Token pasting in #include directive
From: Chris Torek
Date: Tue, 28 Nov 1989 07:03
Date: Tue, 28 Nov 1989 07:03
56 lines
2356 bytes
2356 bytes
>In article <18672@watdragon.waterloo.edu> afscian@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@sdrc.UUCP> scjones@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@cs.umd.edu Path: uunet!mimsy!chris
Technical Details
Message-ID:
<20961@mimsy.umd.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!purdue!haven!mimsy!chrisReferences:
<11160@riks.csl.sony.co.jp> <1989Nov22.222413.3874@utzoo.uucp> <970@sdrc.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!purdue!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.std.c Subject: Re: Token pasting in #include directive Message-ID: <20961@mimsy.umd.edu> Date: 28 Nov 89 07:03:53 GMT References: <11160@riks.csl.sony.co.jp> <1989Nov22.222413.3874@utzoo.uucp> <970@sdrc.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 56