473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

macros again

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

Aug 24 '07 #1
1 1301
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

Aug 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Chris Reedy | last post by:
For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can...
16
by: mike420 | last post by:
Tayss wrote: > > app = wxPySimpleApp() > frame = MainWindow(None, -1, "A window") > frame.Show(True) > app.MainLoop() > Why do you need a macro for that? Why don't you just write
37
by: michele.simionato | last post by:
Paul Rubin wrote: > How about macros? Some pretty horrible things have been done in C > programs with the C preprocessor. But there's a movememnt afloat to > add hygienic macros to Python. Got any...
37
by: seberino | last post by:
I've been reading the beloved Paul Graham's "Hackers and Painters". He claims he developed a web app at light speed using Lisp and lots of macros. It got me curious if Lisp is inherently faster...
11
by: Ben Hetland | last post by:
....in certain cituations they can be useful if not for anything else, then at least for saving a lot of repetetetetetitititive typing. :-) Beyond the point of "do something better instead", I'm...
1
by: n4ixt | last post by:
I have two macros I used to use in VS 2003. I recently tried to import them for use in VS 2005, but they don't seem to work. I open the macro explorer, right click and do run, but it's like VS...
47
by: Emil | last post by:
Is there any hope that new versions of PHP will support macros similar to C or C++? I've searched manual and didn't find anything except define directive, but it can be used to define constant...
11
by: San | last post by:
hi there, I am new to c++ and tryig to learn the basics of the c++ concepts. While I was reading the templates, I realize that the templates are a syntax that the compilar expands pased upon the...
33
by: Robert Seacord | last post by:
When writing C99 code is a reasonable recommendation to use inline functions instead of macros? What sort of things is it still reasonable to do using macros? For example, is it reasonable to...
6
by: Thant Tessman | last post by:
Back before C++ templates, I was taught a trick whereby one built C macros that built other C macros. I can't remember how the heck we did it. The problem is that there seems to be no standard way...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.