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

Error when modifying vector member of another class
Interrupt Service Routine can't be called directly
Lambda capture by default reference vs named
convert bitset<64> to string every 8 bit
argument of type “int” incompatible with parameter of type “int”
When is the correct time to call restoreState for QHeaderView?
How does it pass lvalue reference to std::forward with CRTP?
Using lower_bound function in loop is giving runtime error?
Problems with rand(), always taking the same random generated number [duplicate]
Reading Credentials file fails with error 32
The mechanism of shared_ptr
C++ specialized function template
Compiler errors with cmath on Mac OS X
Array of fstream in C++
Error: (E107) bind interface to port failed: interface already bound to port: port 'MC8051_ALU().AM.port_27' (sc_in)
Error LINK2019 when I try to make a training for face detection [duplicate]

Categories

HOME
java-ee
alexa
powershell-v4.0
local-storage
drools
cakephp-3.0
datatable
windows-installer
houndify
crystal-reports-xi
postgis
strongloop
treeset
log4net
google-play-games
row-number
redactor
j
hudson
recurly
4d-database
couchbase-view
apprtcdemo
swtbot
xfce
google-cloud-vision
ddos
z80
spring-4
side-effects
sqlcedatareader
kinvey
rcp
jung
gmail-contextual-gadgets
sequences
polymer-serve
mapped-drive
android-device-monitor
nsset
gitversion
schemaless
collaborative-filtering
launch-agent
python-wheel
dde
display-bugs
parrot
eclipse-indigo
qtquick2
codeigniter-restserver
testdroid
max-heap
heapsort
acl2
xlet
jaxb2-maven-plugin
childviewcontroller
safari9
wunderlist
voog
compiler-options
review
workbench
editplus
runscope
openacs
hasp
string-conversion
declarative-services
interlacing
phpmotion
sencha-touch-2.2
harfbuzz
rs485
mysql-5.0
jwebunit
vp8
strtotime
icefaces-1.8
ejbql
viewstack
nsformatter
actinic
glow
looper
fibonacci-heap
juggernaut
www-mechanize
widechar
live-cd
pointer-arithmetic
flashlite

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile