Click here to Skip to main content
15,884,950 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Would anyone know of a good book or resource where I can gain a firm understanding of writing C++ macros. Also hopefully something which will cover the preprocessor and the standard macros it uses.

I specifically want to learn more about this side of C++. I realize there are some simple examples out there but my aim is to gain a complete understanding of them. I do undestand them at a basic level but I don't know what I don't know.

Definitely prefer books if possible. Has anyone come across any covering this topic area well.

I have Googled this and asked some colleagues and it seems nobody has heard of a book of this nature. Maybe there's a good web resource on this somebody can recommend.

Thanks.
Posted
Updated 12-Dec-14 23:33pm
v2

It is most unlikely you will find a book on the subject, as macros are not a particularly useful feature. You could take a look at http://msdn.microsoft.com/en-us/library/y4skk93w.aspx[^], which provides details of the preprocessor, including macros.
 
Share this answer
 
How about the C++ standard? It's not easy to read, but definitively the reference.

Go to open-std.org: Working Draft, Standard for Programming
Language C++
[^] or any newer version. The preprocessor has most likely not changed.

There are a few tricky parts in the preprocessor:
- the accepted PP number tokens are not necessarily legal C/C++ literals
- re-evaluation of function macro arguments
- re-evaluation of # and ## PP tokens
- PP expression evaluation is not necessarily the same as for the final program
- handling some special cases (pragmas, line splicing/line numbering, etc.)

Cheers
Andi
 
Share this answer
 
Really, to find out the things you can do just google it.

The important thing to remember is that macros are just preproccesors of text. All of the text substitution takes place before any compiling is done. That is before the C++ language is invoked and before variables exist. Macros are very usfull but always think twice before making an art of using them. They are intended as a textual labour saving device
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900