File: problems_with_compilers.htm

package info (click to toggle)
boost 1.27.0-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 19,908 kB
  • ctags: 26,546
  • sloc: cpp: 122,225; ansic: 10,956; python: 4,412; sh: 855; yacc: 803; makefile: 257; perl: 165; lex: 90; csh: 6
file content (139 lines) | stat: -rw-r--r-- 5,060 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Boost.Preprocessor - Known problems with specific compilers</title>
</head>
<body bgcolor="#FFFFFF" link="#0000ff" vlink="#800080">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
    "header">
  <tr> 
    <td valign="top" width="300"> 
      <h3><a href="../../../index.htm"><img height="86" width="277" alt="C++ Boost" src="../../../c++boost.gif" border="0"></a></h3>
    </td>
    <td valign="top"> 
      <h1 align="center">Boost.Preprocessor</h1>
      <h2 align="center">Known problems with specific compilers</h2>
    </td>
  </tr>
</table>

<hr>

<p> Some compilers have buggy or limited preprocessors. This page explains known 
  problems with specific compilers.</p>
<hr>
<h2>Contents</h2>
<ul>
  <li><a href="#Metrowerks Codewarrior 7.0">Metrowerks Codewarrior 7.0</a></li>
  <li><a href="#Comeau C/C++ 4.2.45.2">Comeau C/C++ 4.2.45.2 for Windows</a></li>
</ul>
<HR>

<h3><a name="Metrowerks Codewarrior 7.0">Metrowerks Codewarrior 7.0</a></h3>
<p>Metrowerks Codewarrior 7.0 has a bug in preprocessor (to be more 
  concrete, in function-like macro replacement mechanism) that restricts usage 
  of the library to only very simple cases, at least if you don't write code that 
  specifically address this issue; for example, the above NUMBERED_EXPRESSION 
  example doesn't compile on CW 7.0. Below is a simple test case that reproduces 
  the bug:</p>
<blockquote>
  <pre>#define IDENTITY_MACRO(x) IDENTITY_MACRO_BODY(x)
#define IDENTITY_MACRO_BODY(x) x
#define COMMA_TOKEN() ,
int a IDENTITY_MACRO(COMMA_TOKEN)() b; // this works
int c IDENTITY_MACRO(IDENTITY_MACRO(COMMA_TOKEN))() d; // this doesn't
</pre>
</blockquote>
<p>Basically, what's happening here is that function-like COMMA_TOKEN macro gets 
  expanded _inside_ of the nested IDENTITY_MACRO call - even although it's NOT 
  followed by a '(' as the next preprocessing token - which is a clearly an incorrect 
  behavior (see 16.3 [cpp.replace] para 9 for the detailed description of the 
  function-like macro replacement process). I've submitted a bug report, but they 
  haven't confirmed it yet.</p>
<p>So, this is not a problem of the library, but probably something that needs 
  to be mentioned in the documentation, may be with some examples of how to workaround 
  the issue. Just to show one possible way around the problem, here is a NUMBERED_EXPRESSION 
  macro that does work on MWCW:</p>
<blockquote>
  <pre>#define NUMBERED_EXPRESSION(n, x) \
    BOOST_PP_CAT(BOOST_, \
    BOOST_PP_IF( \
      n \
    , PREPROCESSOR_IDENTITY(x##n) \
    , PREPROCESSOR_EMPTY \
    ))() \
/**/
</pre></blockquote>
<p align="right"><i>Reported by Aleksey Gurtovoy</i></p>

<h3><a name="Comeau C/C++ 4.2.45.2">Comeau C/C++ 4.2.45.2 for Windows</a></h3>
<p>It appears that their algorithm of macro call invocation is quite far 
  from ideal, because for the following code fragment (which is a part of 
  <a href="../test/preprocessor_test.cpp">preprocessor_test.cpp</a>), the 
  linear increasing of IS_FUNCTION_HELPER_TEST_MAX value leads to not even 
  quadratic, but something like exponential increasing of compilation time! 
  (see the timing data below). This behavior may or may not be problematic
  for you, depending on how intense is your usage of the library.

<blockquote>
  <pre>#ifndef IS_FUNCTION_HELPER_TEST_MAX
#define IS_FUNCTION_HELPER_TEST_MAX 40
#endif

typedef char yes_type;

#define IS_FUNCTION_HELPER(I,A)\
  template\
  &ltBOOST_PP_ENUM_PARAMS(BOOST_PP_INC(I),class P)&gt;\
  yes_type is_function_helper(\
    P0 (*)(BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_INC(I),P)));

BOOST_PP_REPEAT_2ND(BOOST_PP_INC(IS_FUNCTION_HELPER_TEST_MAX),IS_FUNCTION_HELPER,A)

#undef IS_FUNCTION_HELPER
</pre></blockquote>

<h4>Timing data:</h4>
<table border="1">
<tr align="center">
  <th>&nbsp;</th>
  <th>Comeau C/C++ 4.2.45.2</th>
  <th>Microsoft Visual C++ 6.0 SP5</th>
</tr>
<tr align="center">
  <td>10 parameters</td>
  <td><font color="red">&lt; 1 sec</font></td>
  <td>&lt; 1 sec</td>
</tr>
<tr align="center">
  <td>20 parameters</td>
  <td><font color="red">~ 2 sec</font></td>
  <td>&lt; 1 sec</td>
</tr>
<tr align="center">
  <td>30 parameters</td>
  <td><font color="red">~ 15 sec</font></td>
  <td>&lt; 1 sec</td>
</tr>
<tr align="center">
  <td>40 parameters</td>
  <td><font color="red">~ 50 sec</font></td>
  <td>&lt; 1 sec</td>
</tr>
</table>

<p align="right"><i>Reported by Aleksey Gurtovoy</i></p>

<hr>
<p>Revised 
  <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
  <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
<p><i>&copy; Copyright <a href="http://www.housemarque.com">Housemarque Oy</a> 2002</i></p>

<p><i>Permission to copy, use, modify, sell and distribute this document is granted
provided this copyright notice appears in all copies. This document is provided
"as is" without express or implied warranty, and with no claim as to its suitability
for any purpose.</i></p>
</body>
</html>