This is a discussion on New Notation within the C and C++ forums, part of the Programming Talk category; I know that # is used for preprocessor directive in C programming language. But recently I saw in my friend’s ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
New Notation
I know that # is used for preprocessor directive in C programming language. But recently I saw in my friend’s code a new operator with notation as ## but I could not understand what it meant and the usage of the same. Can some one share your experience of this operator ## which would help all members to learn about this new notation.
|
|
|||
|
The # and ## operators are used with the #define macro. Using # causes the first argument after the # to be returned as a string in quotes. Using ## concatenates what's before the ## with what's after it.
-------------------------------------------------------- #define to_string( s ) # s will make the compiler turn this command cout << to_string( Hello World! ) << endl; into cout << "Hello World!" << endl; --------------------------------------------- Here is an example of the ## command: #define concatenate( x, y ) x ## y ... int xy = 10; cout << concatenate( x, y ) << endl; into cout << xy << endl; |
|
|||
|
#define to_string( s ) # s
#include <iostream.h> void main(void){ cout << to_string( string wiout quotes ) << endl; // cout requires quoted string and using macro to_string will return the same } ------------------------------------------------ #define concatenate( x, y ) x ## y #include <iostream.h> void main(void){ in ab = 20; cout << "The your age is " << concatenate(a,b)<<endl; // ab is variable and u want to print is value //the concatinate macro just do the same and result will be ab which is a //varibale declared by you as int // remember output by cancatinate is not a quoted string and will not be // string in any case it will be just concatinated input values if any confusion email me in detail at maksunn@gmail.com } |
![]() |
| Thread Tools | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| comp.specification.z Frequently Asked Questions (FAQ) | zforum-request@comlab.ox.ac.uk | Tech FAQ | 0 | 05-31-2004 10:00 PM |
| comp.specification.z Frequently Asked Questions (FAQ) | zforum-request@comlab.ox.ac.uk | Tech FAQ | 0 | 05-31-2004 10:00 PM |
| UML notation question... | Michael Hartley | Software Patterns | 21 | 05-21-2004 03:39 PM |
| comp.specification.z Frequently Asked Questions (FAQ) | zforum-request@comlab.ox.ac.uk | Tech FAQ | 0 | 04-30-2004 10:00 PM |
| comp.lang.eiffel Frequently Asked Questions (FAQ) | Franck Arnaud | Tech FAQ | 0 | 04-17-2004 08:27 AM |