Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > macros again

Reply
Thread Tools

macros again

 
 
borophyll@gmail.com
Guest
Posts: n/a
 
      08-24-2007
Sorry for my perverse interest in the C preprocessor, but I have a
question about a subtle matter. Yesterday, Eric brought up a point
about the following case, indicating how preprocessing input should be
treated as tokens rather than text. He gave this example

#define A *
#define B /

B* Not a comment A/

While GCC produces the preprocessor output

/ * Not a comment */

This generates 6 tokens. Would it be perfectly valid if I wrote a
preprocessor implementation that would produces 7 tokens as such

/ * Not a comment * /

since technically A and / are separate tokens before being
preprocessed. While GCC seems to combine these two tokens into one, I
guess technically there is nothing wrong with this, since */ is an
invalid token at this stage anyway.

regards, B

 
Reply With Quote
 
 
 
 
Army1987
Guest
Posts: n/a
 
      08-24-2007
On Fri, 24 Aug 2007 04:07:19 +0000, borophyll wrote:

> Sorry for my perverse interest in the C preprocessor, but I have a
> question about a subtle matter. Yesterday, Eric brought up a point
> about the following case, indicating how preprocessing input should be
> treated as tokens rather than text. He gave this example
>
> #define A *
> #define B /
>
> B* Not a comment A/
>
> While GCC produces the preprocessor output
>
> / * Not a comment */
>
> This generates 6 tokens. Would it be perfectly valid if I wrote a
> preprocessor implementation that would produces 7 tokens as such
>
> / * Not a comment * /
>
> since technically A and / are separate tokens before being
> preprocessed. While GCC seems to combine these two tokens into one, I
> guess technically there is nothing wrong with this, since */ is an
> invalid token at this stage anyway.


I think so, but it would be less confusing if it added whitespace
to show the token boundary.
Compare with
#define PLUS +
i+PLUS

it must expand in i+ +, which is a valid sequence because I could
write i+PLUS 5.
If the output of the preprocessor was text, it couldn't be i++
because that's two tokens, i ++, they should be three, i + +.
--
Army1987 (Replace "NOSPAM" with "email")
No-one ever won a game by resigning. -- S. Tartakower

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
macros-loop? calling macros X times? Andrew Arro C Programming 2 07-24-2004 09:52 AM
Explanation of macros; Haskell macros mike420@ziplip.com Python 80 11-07-2003 02:22 AM
Re: Explanation of macros; Haskell macros Michael T. Babcock Python 0 11-03-2003 01:54 PM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 5 11-01-2003 01:09 AM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 1 10-07-2003 04:07 PM



Advertisments