Exforsys

Online Training

New Notation

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 ...


Go Back   Exforsys > Programming Talk > C and C++

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-23-2007, 12:00 AM
Senior Member
 
Join Date: Apr 2006
Posts: 153
cyrus is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-04-2007, 12:44 AM
Junior Member
 
Join Date: May 2007
Posts: 12
Mukhtar Ahmad is on a distinguished road
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;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-06-2007, 07:41 AM
Senior Member
 
Join Date: Apr 2006
Posts: 153
cyrus is on a distinguished road
It was a great explanation on the notation #. Can you give some example in C programming language of this notation #. This would help me to learn more deep about this notation usage.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-07-2007, 12:29 AM
Junior Member
 
Join Date: May 2007
Posts: 12
Mukhtar Ahmad is on a distinguished road
#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
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

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


All times are GMT -4. The time now is 11:59 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.