Topic: Preprocessor's concatenation (##) and string literals.
Author: Hubert HOLIN <Hubert.Holin@meteo.fr>
Date: Tue, 4 Sep 2001 15:24:06 GMT Raw View
Somewhere in the E.U., le 04/09/2001
Hi
According to my (probably flawed) understanding of the standard, the
folowing should output "float". My compiler disagrees. Who's right? A
Google search turned up only irrelevancies.
---- 8>< ---------------------- ><8 ----
#include <iostream>
#define TEST(type) \
::std::cout << "##type" << ::std::endl;
main()
{
TEST(float)
}
#undef TEST
---- 8>< ---------------------- ><8 ----
Hubert Holin
Hubert.Holin@Bigfoot.com
I am not a mad scientist, I am a mad mathematician!
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Ron Natalie <ron@sensor.com>
Date: Tue, 4 Sep 2001 17:51:08 GMT Raw View
Hubert HOLIN wrote:
>
> #define TEST(type) \
> ::std::cout << "##type" << ::std::endl;
>
I think you're confused. The ## glues two tokens together.
It also has to be between two tokens to be the ## operator.
In this case it's embedded in the middle of a string literal
(which is one token in itself).
What you really want is the # preprocessor operator:
#define TEST(type) \
std::cout << #type << std::endl;
#define TEST(float) then maps to
std::cout << "float" << std::endl;
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]