Exforsys

Free 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++

Exforsys.com


C and C++ C and C++

Reply

 

LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 05-22-2007, 11:00 PM
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
Sponsored Links
  #2 (permalink)  
Old 06-03-2007, 11:44 PM
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, 06: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-06-2007, 11:29 PM
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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 09:00 PM
comp.specification.z Frequently Asked Questions (FAQ) zforum-request@comlab.ox.ac.uk Tech FAQ 0 05-31-2004 09:00 PM
UML notation question... Michael Hartley Software Patterns 21 05-21-2004 02:39 PM
comp.specification.z Frequently Asked Questions (FAQ) zforum-request@comlab.ox.ac.uk Tech FAQ 0 04-30-2004 09:00 PM
comp.lang.eiffel Frequently Asked Questions (FAQ) Franck Arnaud Tech FAQ 0 04-17-2004 07:27 AM


All times are GMT -4. The time now is 07:34 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright 2004 - 2009 Exforsys Inc. All rights reserved.