473,321 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

##

nik
hi friends,
plz tell me the use of ##
by giving example

Aug 2 '06 #1
17 1522
nik wrote:
plz tell me the use of ##
by giving example
Plz experiment with google. It finds answers to such things easily. For
instance:

http://www.cppreference.com/preprocessor/sharp.html

Cheers! --M

Aug 2 '06 #2
nik wrote:
plz tell me the use of ##
by giving example
It's the "token pasting" operator. Use it to combine token fragments into a
complete identifier.

Here's a complete, useful example. It tests a WTL dialog box. (Fear not,
topic police, we see little Windows Template Library code here, and the
actual TEST_() macro itself is quite portable.)

I like the TEST_() macro better than the usual Test Suite system (where you

must write extra code to push each Test Case into its Suite's list), so I
wrote a CppUnit clone that uses _only_ the TEST_() macro.

Firstly, all TestCases obey the Abstract Template pattern:

class
TestCase
{
public:
virtual void setUp() {}
virtual void runCase() = 0;
virtual void tearDown() {}
};

Their caller will iterate a polymorphic list of cases, and call setUp(),
runCase(), and tearDown() on each one.

To test a WTL dialog box called ProjectDlg, with a name and address on it,
we write a Suite called TestDialog:

class
TestDialog: public TestCase
{
public:
ProjectDlg m_aDlg;

virtual void setUp()
{ m_aDlg.Create(HWND_TOP); }

virtual void tearDown()
{ m_aDlg.DestroyWindow(); }

TestDialog(): m_aDlg(xml) {}
};

Now we naively derive one concrete class for each of two test cases:

class
TestDialog_first_name: public TestDialog
{
public:
void
runCase()
{
CPPUNIT_ASSERT_EQUAL( "Ignatz",
m_aDlg.getText(IDC_EDIT_FIRST_NAME) );
}
};

class
TestDialog_last_name: public TestDialog
{
public:
void
runCase()
{
CPPUNIT_ASSERT_EQUAL( "Mouse",
m_aDlg.getText(IDC_EDIT_LAST_NAME) );
}
};

Then we get this primordial test rig to pass, using an unrolled version of
the loop we will soon write:

int
main()
{
try {
TestDialog_first_name test1;
test1.setUp();
test1.runCase();
test1.tearDown();

TestDialog_last_name test2;
test2.setUp();
test2.runCase();
test2.tearDown();
}
catch(_com_error & e)
{
guard_(e);
ELIDE_(__asm { int 3 });
return 1;
}
return 0;
}

(Notice, despite I'm using that evil OLE COM ActiveX whatever library from
Microsoft, my code is not full of extra crud like CComBSTR or
CoCreateInstance(). Something chased it all away!)

From here, we need to upgrade TestCase et al to automatically collect the
Test Cases. They should not appear twice - once among the test suites and
again in main(). Removing behavioral duplication tends to improve code's
style.

Make each TestCase instance push itself into a static member list:

#include <list>

class
TestCase
{
public:
typedef std::list<TestCase *TestCases_t;
TestCases_t static cases;

TestCase() { cases.push_back(this); }
virtual void setUp() {}
virtual void runCase() = 0;
virtual void tearDown() {}
};

TestCase::TestCases_t TestCase::cases;
....
class
TestDialog_last_name: public TestDialog
{
public:
void
runCase()
{
CPPUNIT_ASSERT_EQUAL( "Mouse",
m_aDlg.getText(IDC_EDIT_LAST_NAME) );
}
};
TestDialog_last_name test2;

(Remember that after each few edits all tests must still pass!) Now upgrade
main() to use the list:

int
main()
{
try {
TestCase::TestCases_t::iterator it (TestCase::cases.begin());

for ( ; it != TestCase::cases.end(); ++it )
{
TestCase & aCase = **it;
aCase.setUp();
aCase.runCase();
aCase.tearDown();
}
}

We continue to seek things that look similar, make them the same, and merge
their duplication.

The classes TestDialog_first_name (not shown) and TestDialog_last_name now
look very similar, but so do their object instances. To make them all the
same, we need to declare a class and instantiate an object in one command:

#define TEST_(suite, target) \
struct suite##target: public suite \
{ void runCase(); } \
a##suite##target; \
void suite##target::runCase()

TEST_(TestDialog, first_name)
{
CPPUNIT_ASSERT_EQUAL( "Ignatz",
m_aDlg.getText(IDC_EDIT_FIRST_NAME) );
}

TEST_(TestDialog, last_name)
{
CPPUNIT_ASSERT_EQUAL( "Mouse",
m_aDlg.getText(IDC_EDIT_LAST_NAME) );
}

The object instances went inside the TEST_() macro, which uses
token##pasting to give them unique names. But they all must construct,
globally, so their constructors can register them with the list of cases.

This pattern makes Test Fixtures easy. Classes like TestDialog take care of
setting up and tearing down tested objects, providing a framework to share
other common operations on the tested objects. Test cases are now easy. The
Test Collector pattern ensures when we write new cases, we can't forget to
add them to a remote list of cases.

But these Test Cases no longer look like normal C++ functions!

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Aug 2 '06 #3
mlimber wrote:
Plz experiment with google. It finds answers to such things easily. For
instance:

http://www.cppreference.com/preprocessor/sharp.html
Oh, a # is called a "sharp" today?

Wait 24 hours... ;-)

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Aug 2 '06 #4
Phlip wrote:
mlimber wrote:
>Plz experiment with google. It finds answers to such things easily. For
instance:

http://www.cppreference.com/preprocessor/sharp.html

Oh, a # is called a "sharp" today?
Well, it looks similar, but actually isn't one.
See http://en.wikipedia.org/wiki/Number_sign
Aug 2 '06 #5
Rolf Magnus wrote:
>Oh, a # is called a "sharp" today?

Well, it looks similar, but actually isn't one.
See http://en.wikipedia.org/wiki/Number_sign
What does the ISO C++ Standard call it?

Would Googling for that (if the OP could have figured out what to Google
for) possibly have worked?

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Aug 2 '06 #6
Phlip <ph******@yahoo.comwrote:
What does the ISO C++ Standard call it?
<ot>Microsoft has said the following concerning C#:

"The spoken name of the language is "C sharp" in reference to the
musical "sharp" sign, which increases a tone denoted by a letter
(between A and G) by half a tone. However, for ease of typing it was
decided to represent the sharp sign by a pound symbol [3] (which is on
any keyboard) rather than the "musically correct" Unicode sharp
sign. The Microsoft and ECMA 334 representation symbols thus agree:
the # in C# is the pound sign, but it represents a sharp sign. Think
of it in the same way as the <= glyph in C languages which is a less
than sign and an equals sign, but represents a less-than-or-equals
sign."</ot>

On a somewhat more topical note, the n869 draft of the C standard only
names the '#' once and calls it a "sharp sign".

One could always call it an "octothorpe" :-)

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Aug 2 '06 #7

Phlip wrote:
Rolf Magnus wrote:
Oh, a # is called a "sharp" today?
Well, it looks similar, but actually isn't one.
See http://en.wikipedia.org/wiki/Number_sign

What does the ISO C++ Standard call it?
"The # operator"

It's actually an "octothorpe".

Aug 2 '06 #8
Noah Roberts wrote:
"The # operator"

It's actually an "octothorpe".
The great thing about Standards is there are so many to mislead your
competition...

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Aug 2 '06 #9
Christopher Benson-Manica wrote:
On a somewhat more topical note, the n869 draft of the C standard only
names the '#' once and calls it a "sharp sign".
The final version does that too. The C++ standard doesn't even contain the
word "sharp" at all. AFAICS, it doesn't give that symbol any name at all.
Aug 2 '06 #10
Rolf Magnus <ra******@t-online.dewrote:
The final version does that too. The C++ standard doesn't even contain the
word "sharp" at all. AFAICS, it doesn't give that symbol any name at all.
That seems to have been a wise decision on the Committees' parts.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Aug 2 '06 #11
Christopher Benson-Manica <at***@otaku.freeshell.orgwrote:
On a somewhat more topical note, the n869 draft of the C standard only
names the '#' once and calls it a "sharp sign".

One could always call it an "octothorpe" :-)
Sometimes I feel the need to call it "pound". As in, I pronounce
#include as "pound include".

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Aug 2 '06 #12
Marcus Kwok wrote:
Sometimes I feel the need to call it "pound". As in, I pronounce
#include as "pound include".
As a Brit, I prefer to call it "hash" as in "hash include" or "hash
define". My American coworkers think I'm strange...

Aug 2 '06 #13
Rat Monkey Hybrid wrote:
Marcus Kwok wrote:
>Sometimes I feel the need to call it "pound". As in, I pronounce
#include as "pound include".

As a Brit, I prefer to call it "hash" as in "hash include" or "hash
define". My American coworkers think I'm strange...
We are all strange for keeping coming back to "discuss" this nonsense.
Aug 2 '06 #14

Rat Monkey Hybrid wrote:
My American coworkers think I'm strange...
A logical conclusion, but not for the reason you seem to think.

Aug 2 '06 #15
Rat Monkey Hybrid posted:
Marcus Kwok wrote:
>Sometimes I feel the need to call it "pound". As in, I pronounce
#include as "pound include".

As a Brit, I prefer to call it "hash" as in "hash include" or "hash
define". My American coworkers think I'm strange...

I too say "hash include". In Europe, the pound sign is this:

http://www.afme.org.uk/res/img/resources/Pound.jpg

and it represents the currency of Britain.

--

Frederick Gotham
Aug 2 '06 #16
Frederick Gotham wrote:
Rat Monkey Hybrid posted:

>>Marcus Kwok wrote:
>>>Sometimes I feel the need to call it "pound". As in, I pronounce
#include as "pound include".

As a Brit, I prefer to call it "hash" as in "hash include" or "hash
define". My American coworkers think I'm strange...

I too say "hash include". In Europe, the pound sign is this:

http://www.afme.org.uk/res/img/resources/Pound.jpg

and it represents the currency of Britain.
In Dutch: hekje include :)
Aug 2 '06 #17
Phlip wrote:
mlimber wrote:
>Plz experiment with google. It finds answers to such things easily. For
instance:

http://www.cppreference.com/preprocessor/sharp.html

Oh, a # is called a "sharp" today?

Wait 24 hours... ;-)
OCTOTHORP.

--
Mike Smith
Aug 4 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.