| Summary: | write_stream macro fails in 'if' statement | ||
|---|---|---|---|
| Product: | [Tools] TCF | Reporter: | Chris Wyse <chris.wyse> |
| Component: | Core | Assignee: | 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: | |||
Fixed by wrapping into do...while(0) Thanks. |
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.