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

C++ bitmap to hold binary flags
Can I use ndk GLES 2 with c++ shared library
CPPUNIT_ASSERT_EQUAL on std collections
Disable Windows/Home capacitive button programmatically C++
Qt access variable from custom object from QGridLayout
Why can a “hello world” c++ program raise so many “iosfwd” errors in visual studio 2015?
What is the difference between a normal type and an atomic type?
C++: Clean way to create a std::map of function pointers
Why QLocalSocket is designed to be connected only to local pipes in “Windows”?
C++ std::plus as template parameter
g++ : was not declared in this scope despite included header
vector in map in map
Boost Graph Library - Push vector into edge property
OpenMP Dynamic vs Guided Scheduling
String and Cycle
How to handle segmentation fault: 11 c++ osx

Categories

HOME
menu
sitecore8
composer-php
junit
drools
umbraco7
get
imageview
directshow
delay
codeception
interaction
treeset
bit-manipulation
google-login
rinsim
clang-format
bind
intercept
xbuild
uiinterfaceorientation
face-api
filepicker.io
avaya
puma
cloudfoundry-uaa
word
regex-negation
javapoet
hashcode
product-key
umbraco-mvc
uisearchbar
xfs
oracle-ebs
devexpress-wpf
oclazyload
gemfile
background-position
rt
friend-function
cakephp-3.3
matlab-uitable
android-build
erlang-shell
sqlcommand
munin
pandorabots
countdowntimer
kindle
ubuntu-15.10
nsolid
rc4-cipher
classname
gethostbyname
google-roads-api
firefox-addon-bootstrap
spawn-fcgi
stl-format
sonarqube-5.4
polymer-designer-tool
dfdl
wx
html5builder
angularjs-ng-options
github-linguist
event-loop
code-completion
date-arithmetic
rot13
review
opencv-features2d
pegjs
mathgl
svggraph
cvxopt
iunknown
django-staticfiles
ruby-on-rails-plugins
capability
lytebox
custom-view
dvorak
32feet
glow
mindmapping
juggernaut
test-environments
nsenumerator
language-theory
showmodaldialog
blogml
visual-programming
microsoft.build

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile