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

Create JSON structure based on input variables
C++ range for loop different than regular for loop [closed]
C++ boost thread causes segmentation fault when instantiated twice
c++ - 3 bears in a vector of a struct, how can I change this code so the specific bear at the exit is removed?
Reading from excel/text file without skipping whitespaces unless made by a tab
How to initialize const size array in constructor without explicitly stating the size in class declaration?
Reading txt file into 2d array C++
How can I mark a function with an attribute conditionally on the value of a parameter?
Read a text file and store into two different arrays: a string array and float array
converting constructor: How do you explain a function given different arguments in c++
Background in Qt multiplies instead of fitting into window size
C++ pause this program using cin.get()
linking error in utility::conversions::to_string_t in qt creator
readLine() not being saved properly
Check socket with select() before using send()
Error: “Function” not declared in this scope

Categories

HOME
angular
cordova
datatables
reverse-geocoding
composer-php
hardware
function
fiware
uitableview
python-3.6
metal
javafx-2
geoserver
amazon-cloudsearch
datepicker
fontforge
shogun
jlabel
sensenet
google-fusion-tables
pyside
summary
django-channels
robotium-recorder
ggiraph
webm
gmail-contextual-gadgets
asn.1
lightgallery
transitions
oracle-data-modeler
sencha-architect
fixture
android-optionsmenu
sw-precache
paypal-adaptive-payments
jquery-ui-widget-factory
rufus-scheduler
appharbor
lpc
fluentbootstrap
wso2-appm
heyzap
unicode-string
topshelf
fixed
helium
mockery
nsthread
client-side
ienumerable
timedelta
classname
django-class-based-views
little-endian
highcharts-ng
arrangeoverride
pagerslidingtabstrip
mpld3
nameerror
7digital
xcode-bots
avm2
merit-gem
sql-server-2008-express
streaminsight
qmediaplayer
rich-snippets
build-system
avaloq-script
automapper-3
member
tankauth
sharepoint-clientobject
syntactic-sugar
linq-to-lucene
kendo-validator
println
android.mk
icommand
jvm-crash
dynamic-languages
visual-studio-test-runner
32feet
twisted.internet
ext-direct
endl
wcsf
statusnet
layar
juggernaut
multiple-versions
live-cd
libjson
projective-geometry
abbreviation
comdlg32

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile