Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 369102

Summary: write_stream macro fails in 'if' statement
Product: [Tools] TCF Reporter: Chris Wyse <chris.wyse>
Component: CoreAssignee: Project Inbox <tcf.core-inbox>
Status: RESOLVED FIXED QA Contact: Eugene Tarassov <eugene>
Severity: normal    
Priority: P3 CC: cdtdoug
Version: unspecified   
Target Milestone: 1.0.0   
Hardware: All   
OS: All   
Whiteboard:

Description Chris Wyse CLA 2012-01-19 11:06:36 EST
Build Identifier: 

The write_stream macro doesn't work properly inside an 'if' statement.

For example:

if (condition)
   write_stream(x, y);
else
   <statement>;

Expands to:

if (condition)
    { OutputStream * _s_ = (x); int _x_ = (y); 
      if (_x_ > ESC && _s_->cur < _s_->end) 
         *_s_->cur++ = (unsigned char)_x_;       
      else 
         _s_->write(_s_, _x_); 
    };
else
   <statement>;

The problem is the ';' after the brace before the 'else'.  That semi-colon terminates the 'if' statement, so the following 'else' generates an error when compiled.

One possible solution would be to define the macro like this:

#define write_stream(x,y) if (1) { <code> } else  

It looks a little ugly - maybe there is a better way.  

Reproducible: Always

Steps to Reproduce:
1.See above
2.
3.
Comment 1 Eugene Tarassov CLA 2012-01-19 14:23:01 EST
Fixed by wrapping into do...while(0)
Thanks.