473,775 Members | 2,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

commenting out 'cout' using preprocessor macro

I hope comp.lang.c will not find the following question as a
complete off-topic.

I would like to remove ie.comment out the 'cout' statements during
compilation(act ually preprocessing) time.
The statements like this:
cout<<"somethin g\n" ;
should be made as
// cout<<"somethin g\n" ;
I tried for the following. But, It doesn't seem to be working.
//--------START
#ifdef DEBUG
#define COUT std::cout
#else
#define COUT \/\/
#endif

int main()
{
COUT<<"HELLO\n" <<std::endl ;
}

//--------END
If you can solve the above problem, please suggest a way for taking
care of
commenting out the 'cout' statements that spans in more than 1 line.
eg:

12 COUT<<"HELLO\n"
13 <<"WORLD\n" ;
Nov 13 '05
18 6794

"Samuele Armondi" <sa************ ****@hotmail.co m> wrote in message
news:3f******** @mk-nntp-1.news.uk.world online.com...
"qazmlp" <qa********@red iffmail.com> wrote in message
news:db******** *************** ***@posting.goo gle.com...
I hope comp.lang.c will not find the following question as a
complete off-topic.
[snip...] But you would need to be 100% sure that the code in question does not use
the << _anywhere_. Hope this helps anyway!
S. Armondi

Sorry, ignore all the \ in the declaration of the MyStream class. They are
not needed.
S. Armondi
Nov 13 '05 #11

after the phase 3 of the translation in both languages.

Victor


What exactly is phase 3 translation? Into assembly or RTL perhaps?

Bill

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
Nov 13 '05 #12

"Victor Bazarov" <v.********@att Abi.com> wrote in message news:vj******** ****@corp.super news.com...
"Jeff" <no****@notexis t.com> wrote...

"qazmlp" <qa********@red iffmail.com> wrote in message
news:db******** *************** ***@posting.goo gle.com...
I hope comp.lang.c will not find the following question as a
complete off-topic.

I would like to remove ie.comment out the 'cout' statements during
compilation(act ually preprocessing) time.
The statements like this:
cout<<"somethin g\n" ;
should be made as
// cout<<"somethin g\n" ;
Sorry, it is off-topic here. cout is a part of C++, not C.


Sorry, Jeff, statements explaining what is off-topic in
comp.lang.c are off-topic in comp.lang.c++. And give "qazmlp"
a break, he expressed his hope, didn't he?


Sorry, Victor, statements explaining the other is off-topic here is also off-topic.

Unfortunately, you are off-topic now.

(Just to remind you, we have the right to protect our c.l.c group from off-topic by kindly notifying
the OP. It is usual on Usenet and I am not the first one. If you insist that the OP is not off-topic
here, you can give your opinion)
Victor


--
Jeff
Nov 13 '05 #13
On Fri, 8 Aug 2003 23:57:54 -0400, "Bill Cunningham" <so**@some.ne t>
wrote in comp.lang.c:

after the phase 3 of the translation in both languages.

Victor


What exactly is phase 3 translation? Into assembly or RTL perhaps?

Bill


The original ANSI/ISO C language standard (1989/1990) provided a
high-level definition of the translation process that an
implementation performs in producing executable code from a source
file. These have persisted to the present in later versions of the C
standard and have been incorporated into the C++ standard.

Like everything else in C and C++, the "as-if" rule applies, meaning
that a compiler does not have use separate passes to perform all of
these operations. It can do them in parallel as long as the proper
ordering is used.

They are too long to quote here in full, but the two that are relevant
to this question are that in phase 3, "Each comment is replaced by one
space character", and in phase 4, "Preprocess ing directives are
executed and macro invocations are expanded".

So there is no way of including a comment in the expansion of a macro.
The early lexical analysis step removes comments before the
preprocessor expands macros.

An overview of the 8 phases of translation:

1 through 6 deals with parsing and preprocessor issues. At the end of
phase 6 the program is a series of tokens, without white space, with
all comments removed and macros expanded.

Phase 7 actually analyses and translates the program into some sort of
output format, generally referred to as an object file.

Phase 8 is after compilation, usually performed by a separate tool
called a linker. It resolves references between different source
files and to library modules and generally produces the final
executable output file.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #14
"Jeff" <no****@notexis t.com> wrote...
[...]
Sorry, Victor, statements explaining the other is off-topic here is also off-topic.

REALLY?
Unfortunately, you are off-topic now.

(Just to remind you, we have the right to protect our c.l.c group from off-topic by kindly notifying the OP. It is usual on Usenet and I am not the first one. If you insist that the OP is not off-topic here, you can give your opinion)


I already have. If you need it again, go to my first reply to you
and re-read it.
Nov 13 '05 #15
qazmlp wrote:
I would like to remove ie.comment out the 'cout' statements during
compilation(act ually preprocessing) time.


I saw this in a computer mag once (either C++ journal or something like
that):

#ifdef DEBUG
#define SLASH(s) /##s
#define COMMENT SLASH(/)
#else
#define COMMENT std::cout
#endif

Unfortunately, I don't know how portable this is (someone could probably
explain why it won't work). I could get it working on VisualC++ v6, but
had problems with GCC v2.9x. Think it worked in aCC (the HPUX compiler)

--
John L. Fjellstad
Nov 13 '05 #16
John L Fjellstad <jo*******@fjel lstad.org> writes:
I saw this in a computer mag once (either C++ journal or something like
that):

#ifdef DEBUG
#define SLASH(s) /##s
#define COMMENT SLASH(/)
#else
#define COMMENT std::cout
#endif

Unfortunately, I don't know how portable this is (someone could probably
explain why it won't work).


Comments are removed (or rather replaced by a whitespace character) in
translation phase 3, while preprocessing directives are executed and macros
are expanded in translation phase 4. Therefore, `//' is not a meaningful
preprocessing token at the point when `COMMENT' is expanded.

Martin
Nov 13 '05 #17
Martin Dickopp wrote:
Comments are removed (or rather replaced by a whitespace character) in
translation phase 3, while preprocessing directives are executed and
macros are expanded in translation phase 4. Therefore, `//' is not a
meaningful preprocessing token at the point when `COMMENT' is expanded.


Do you know if this is in the C++ standard, or if it is left to the
implementation?

--
John L. Fjellstad
Nov 13 '05 #18
John L Fjellstad <jo*******@fjel lstad.org> writes:
Martin Dickopp wrote:
Comments are removed (or rather replaced by a whitespace character) in
translation phase 3, while preprocessing directives are executed and
macros are expanded in translation phase 4. Therefore, `//' is not a
meaningful preprocessing token at the point when `COMMENT' is expanded.


Do you know if this is in the C++ standard, or if it is left to the
implementation?


This behavior is required by the C++ standard (section 2.1#1) as well as the
C standard (section 5.1.1.2#1).

Martin
(Followup-To: comp.lang.c++ ignored, since the discussion seems meaningful
to both C and C++.)
Nov 13 '05 #19

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

Similar topics

19
1501
by: qazmlp | last post by:
I hope comp.lang.c will not find the following question as a complete off-topic. I would like to remove ie.comment out the 'cout' statements during compilation(actually preprocessing) time. The statements like this: cout<<"something\n" ; should be made as
205
10704
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
5
1907
by: Eric Lilja | last post by:
Using a macro, can I change what type an object is being cast to? I know, the initial respone to question might be an instinctive "ugly, don't even think about it!" or "don't use macros at all", but I still would like to know because I am trying to encapsulate a third-party C-based callback-oriented gui toolkit inside C++ classes and I would like to try something. So say you have: long some_address = some_valid_address;
16
4504
by: Trying_Harder | last post by:
Is it possible to redefine a macro with global scope after undefining it in a function? If yes, could someone explain how? /If/ my question above isn't very clear you can refer to the following example. eg cosider 2 files sample.c and sample.h sample.h
2
6646
by: Paolo | last post by:
I imported a VC++6.0 project into VC++7.1. The conversion operation makes a mess with Preprocessor Definitions, adding a "$(NoInherit)" for each file. For example: I had a DLL project in VC++6.0 where the definitions were: _UNICODE,_DEBUG,_WIN32_DCOM,WIN32,_WINDOWS,_WINDLL,_AFXDLL,_USRDLL In VC++7.1, these are the preprocessor definitions of the project (right-click the project in Solution Explorer and choose Properties -> C++ ->...
8
2922
by: claus.tondering | last post by:
I need to write a macro that inserts someStruct m_someStruct; into another struct declaration. The problem is that if the programmer specifies one particluar struct (called alpha), nothing should be inserted. So, is it possible to write a macro that does this: MACRO(alpha) expands to nothing
100
4762
by: Angel Tsankov | last post by:
Can someone recommend a good source of C/C++ coding style. Specifically, I am interested in commenting style and in particular how to indent comments and the commented code, rather than when to use comments. Thanks in advance! -- http://www.gotw.ca/resources/clcm.htm for info about ]
0
9455
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10111
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9917
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6719
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5364
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4021
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3613
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.