c++


Why does sequence iteration work in C macro?


When writing C macro, there is a trick called "sequence iteration". It looks like as follow:
#define CAT(a, ...) PRIMITIVE_CAT(a, __VA_ARGS__)
#define PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__
#define FUNCTION(name) void name();
#define FUNCTION_TABLE(seq) CAT(FUNCTION_TABLE_1 seq, _END)
#define FUNCTION_TABLE_1(x) FUNCTION(x) FUNCTION_TABLE_2
#define FUNCTION_TABLE_2(x) FUNCTION(x) FUNCTION_TABLE_1
#define FUNCTION_TABLE_1_END
#define FUNCTION_TABLE_2_END
FUNCTION_TABLE((x) (y) (z) (e))
The sequence, i.e. the argument of FUCTION_TABLE, will be processed one by one. However, as far as I know, a token will not be expanded twice in the same scope. Because it is "painted blue". When FUNCTION_TABLE_2 is expanded, the macro FUNCTION_TABLE_1 has already been painted yet. Why is it still expanded?

Related Links

What is the difference between these different ways to invoke an operator on `this`?
Saving variables after a form is closed in WinForms with C++
How to call OnEraseBkgnd() to repaint the window in another function? (MFC)
How can I convert this C# foreach code to C++?
Dynamic int pointer address? [duplicate]
x86 MASM - passing and accessing a 2D array
Boost.spirit x3 compiler error when using semantic action in VS15
g++ undefined reference with a shared library [duplicate]
How can I pass an ifstream as argument to std::thread function?
File handling in c++ to read two integers
linux scheduling to strictly prefer higher priority thread than low priority thread
Returning reference using a ternery expression causes runtime error
In which cases is it okay to allocate on the stack
Simplest way to know a class's type
Draw a vector<glm::vec3> opengl c++
Normal member methods with same name as templated member methods

Categories

HOME
node.js
momentjs
jsoup
g2o
slack
external
jaxb
pivot-table
jspdf
wmi-query
ietf-netmod-yang
atlassian-sourcetree
httpsession
google-nativeclient
probability-theory
cdb
angle
robotium-recorder
endpoints-proto-datastore
ddos
data-migration
white
radius
neoscms
podcast
infowindow
get-eventlog
easymock
web.py
oracle-ebs
event-listeners
mapped-drive
parasoft
nsset
evosuite
rt
smo
cakephp-3.3
strconv
equation-solving
orders
implicit
topshelf
miva
google-keep
decompression
rational-team-concert
eclipse-indigo
groovy-eclipse
ntfs-3g
traceroute
pdf-extraction
pagerslidingtabstrip
cirqus
zurb-foundation-5
argo
singularitygs
stompjs
du
angularjs-ng-options
tap
pixman
maven-site-plugin
google-plugin-eclipse
filefield
ilias
workbench
orca
duplicate-removal
runscope
kendo-validator
complete.ly
stubs
contactscontract
stencils
tiles2
file-association
wexitstatus
ipad-2
customer-support
glow
snk
cocos2d-python
openflashchart2
context-sensitive-help
language-theory
pdc2008

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App