- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello. I'm found a bug with tokens concatenation. Simple example to reproduce:
#define test(x, y) sizeof(x##y) #define test2(x, y) sizeof(##x##y) int main() { int a = test(in, t); // works fine int b = test2(in, t); // error }
Compilation on windows (msvc integration):
1> main.cpp 1>..\main.cpp(6): error : identifier "in" is undefined 1> int b = test2(in, t); // error 1> ^ 1> 1>..\main.cpp(6): error : expected a ")" 1> int b = test2(in, t); // error
Preprocessor output to file:
#line 1 "..\\main.cpp" int main() { int a = sizeof(int); int b = sizeof(int); }
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are correct that we should try to emulate what Microsoft is doing, but your code is definitely incorrect according to the standard.
The GNU compiler gives this error:
sptxl15-134> g++ -c main.cpp
main.cpp:9:1: error: pasting "(" and "in" does not give a valid preprocessing token
sptxl15-135>
The token paste operator must result in a valid token and the second expansion does not have one.
https://gcc.gnu.org/onlinedocs/cpp/Concatenation.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the answer. I am found it by accident, when a working project didn't builded after replacing MSVC to ICC 17. The similar code also worked with ICC for linux. So, I was thinked that it's a bug. But in fact, the work of this code is not necessary, this situation was caused by a typo when copypasting. It will be enough to display a correct error message like it does GCC.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page