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

Using deduced types in other function templates, argument
Trouble with Polygon in Stroustrup's PPP book
Is there a case missing in §8.5 p17 (semantics of initializers) of N3797?
Migrating from Boost to the Standard Library for C++11
Perfect-forwaring of the variadic template parameters of a struct
Force Program to Start As Root and Drop it later
Is the memory initialization/deletion so time-consuming?
Debugging CUDA - CudaUnknownError
Simple decoding program C++ [closed]
Qt Application Slowing Down
How to Set a Class Instance Name to a Variable (C++)
DirectX 11 Make a square.
DeleteTimerQueueTimer() access violation and/or deadlock [closed]
Can the number of parameters determined by templates in c++?
Handling hotkeys with modifiers
HippoMocks With weak_ptr

Categories

HOME
excel
cron
selenium-chromedriver
properties
payment
integration-testing
uwp-xaml
boost
mips32
ais
formula
google-cardboard
crystal-reports-xi
jasperserver
flannel
outlook-redemption
pthreads
benchmarking
hudson
libcurl
intercept
face-api
gembox-document
ractivejs
sandbox
dsolve
uppaal
inversifyjs
neo4jclient
jquery-chosen
multiple-domains
rcp
slamdata
artoolkit
lsmeans
gperftools
basic4android
rrd4j
angularjs-ng-model
uicollectionviewcell
userfrosting
audiokit
regedit
android-auto
falcor
ole
burn
enterprise-library-6
tableau-public
api-manager
friend-function
django-media
opensmtpd
istanbul
c#-to-vb.net
cscore
audacity
kmip
antivirus-integration
openoffice-writer
groovy-eclipse
django-class-based-views
xcode4
inventory
iterm
octopress
stunnel
datamapper
episerver-6-r2
johnny-five
youtube-javascript-api
max-heap
msbuildcommunitytasks
ti-nspire
undefined-symbol
xcode-bots
merit-gem
authentication-flows
voog
lightroom
code-completion
compiler-options
enplug-sdk
jquery-dropkick
image-manipulation
componentkit
rails-i18n
worklight-studio
android-3.0-honeycomb
c++builder-6
stackmob
mib
remotipart
outlook-2003
mysql-5.0
mysql-error-1052
xemacs
wymeditor
actinic
bionic
kiln
xcode4.1
equivalent
tomahawk
tao
context-sensitive-help
httpverbs
duck-typing
maintaining-code

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