Bug 640 - NS_LOG_UNCOND and NS_LOG macros
NS_LOG_UNCOND and NS_LOG macros
Status: RESOLVED INVALID
Product: ns-3
Classification: Unclassified
Component: core
ns-3-dev
All All
: P5 minor
Assigned To: Carlo Bellettini
: patch
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-07-15 18:17 EDT by Carlo Bellettini
Modified: 2009-07-16 15:32 EDT (History)
1 user (show)

See Also:


Attachments
Macros arguments now bracketed in expansion (912 bytes, patch)
2009-07-15 18:17 EDT, Carlo Bellettini
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlo Bellettini 2009-07-15 18:17:52 EDT
Created attachment 533 [details]
Macros arguments now bracketed in expansion

I noticed this in ns-3.5. In core/log.h +307, it'd be useful to rewrite the NS_LOG_UNCOND macro as:

std::clog << (msg) << std::endl;

so that lower precedence operators like in NS_LOG_UNCOND(cond ? a : b) won't require extra bracketing.

the same holds for NS_LOG.

patch for ns-3.5 (release) attached
Comment 1 Mathieu Lacage 2009-07-16 03:23:21 EDT
1) don't mark bugs as "fixed" unless they are "fixed" in ns-3-dev. 
2) I tried your patch and it fails to build:

[272/702] cxx: src/core/object-base.cc -> build/debug/src/core/object-base_1.o
../src/core/object-base.cc: In member function ‘void ns3::ObjectBase::ConstructSelf(const ns3::AttributeList&)’:
../src/core/object-base.cc:63: error: no match for ‘operator<<’ in ‘"construct tid=" << ns3::TypeId::GetName() const()’
../src/core/type-id.h:372: note: candidates are: std::ostream& ns3::operator<<(std::ostream&, ns3::TypeId)
../src/core/object-base.cc:69: error: no match for ‘operator<<’ in ‘"try to construct \"" << ns3::TypeId::GetName() const()’
../src/core/type-id.h:372: note: candidates are: std::ostream& ns3::operator<<(std::ostream&, ns3::TypeId)
../src/core/object-base.cc:85: error: no match for ‘operator<<’ in ‘"construct \"" << ns3::TypeId::GetName() const()’
../src/core/type-id.h:372: note: candidates are: std::ostream& ns3::operator<<(std::ostream&, ns3::TypeId)
../src/core/object-base.cc:103: error: no match for ‘operator<<’ in ‘"construct \"" << ns3::TypeId::GetName() const()’
../src/core/type-id.h:372: note: candidates are: std::ostream& ns3::operator<<(std::ostream&, ns3::TypeId)
../src/core/object-base.cc:134: error: no match for ‘operator<<’ in ‘"construct \"" << ns3::TypeId::GetName() const()’
../src/core/type-id.h:372: note: candidates are: std::ostream& ns3::operator<<(std::ostream&, ns3::TypeId)
../src/core/object-base.cc:150: error: no match for ‘operator<<’ in ‘"construct \"" << ns3::TypeId::GetName() const()’
../src/core/type-id.h:372: note: candidates are: std::ostream& ns3::operator<<(std::ostream&, ns3::TypeId)
Waf: Leaving directory `/home/mlacage/code/ns-3-dev/build'
Build failed
 -> task failed (err #1): 
	{task: cxx object-base.cc -> object-base_1.o}


I have to confess that I don't see how what you are proposing could possibly work. I would tend to mark this bug INVALID unless you come up with a new version of your patch which works.
Comment 2 Carlo Bellettini 2009-07-16 04:15:17 EDT
actually, that patch does solve that very particular issue, but also leads to invalidate handy expressions involving << like in NS_LOG_UNCOND("i = " << 3), since ("i = 3" << 3) is hardly convertible to an ostream...

an extra pair of brackets in very special circumstances is probably a more than acceptable workaround, but other suggestions are welcome.
Comment 3 Mathieu Lacage 2009-07-16 05:24:21 EDT
so you are ok if I mark this as INVALID ?
Comment 4 Carlo Bellettini 2009-07-16 12:52:15 EDT
(In reply to comment #3)
> so you are ok if I mark this as INVALID ?
> 

with no other suggestions, I think it'd be appropriate.