Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 369102 - write_stream macro fails in 'if' statement
Summary: write_stream macro fails in 'if' statement
Status: RESOLVED FIXED
Alias: None
Product: TCF
Classification: Tools
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 1.0.0   Edit
Assignee: Project Inbox CLA
QA Contact: Eugene Tarassov CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-19 11:06 EST by Chris Wyse CLA
Modified: 2013-06-05 05:42 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.