2

I'm trying to compile the SymbolicC++ library in VC++ 2010 Express (there is special VS project in the distribution), but it gives a lot of errors in system headers, related to operator,. For example:

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xlocmon(410): error C2593: 'operator ,' is ambiguous

For this code in a system header:

if (_Str[0] < _E0 || _E0 + 9 < _Str[0])
    _Str2 += '-', ++_Off;

Why? How to compile it?

user7116
  • 63,008
  • 17
  • 141
  • 172
artem
  • 16,382
  • 34
  • 113
  • 189

5 Answers5

5

Apparently, SymbolicC++ has overloaded operator, in such a manner that a downstream include has been affected.

You should reorder your includes such that SymbolicC++'s include comes last:

#include <iostream>
#include <vector>

// don't want to monkey with our other headers
#include "symbolicc++.h"

This isn't to say the code in the <xlocmon> header isn't suspect, that sort of abuseusage of the comma operator is asking for trouble.

user7116
  • 63,008
  • 17
  • 141
  • 172
  • Interesting, well then SymbolicC++ abused the comma operator in a manner that caused a downstream include to barf. – user7116 Mar 08 '12 at 15:25
  • Basically you need to take care to ensure `symbolicc++.h` does not get included before any of the system header files. – user7116 Mar 08 '12 at 16:35
  • @RankoR: Learn to judge by content, not by badge ;) – Sebastian Mach Mar 08 '12 at 16:50
  • @sixlettervariables We're you able to get the SymbolicC++ library to actually build? I'm running into the same issue, but am not sure which headers to reorder. – dharmatech Nov 25 '12 at 22:47
  • The file `verylong.h` includes `` which in turn includes ``. The trouble is that `symbolicc++.h` includes `verylong.h` and later includes `symbolicc++.h` 3 more times. It seems like it would be quite tricky to reorder the headers in a way that doesn't trigger the ambiguity error. – dharmatech Dec 12 '12 at 07:38
2

Here's another workaround which avoids having to modify <xlocmon>.

The dependency on <xlocmon> is via verylong.h which includes <iomanip> which in turn includes <xlocmon>. In verylong.h, comment out the line:

#include <iomanip>

After doing this, the build completes successfully on my system (Windows 7, Visual C++ 2010 Express).

dharmatech
  • 8,979
  • 8
  • 42
  • 88
  • For detailed instructions on getting SymbolicC++ to run in Visual C++ 2010 Express, see [this StackOverflow](http://stackoverflow.com/questions/10679416/how-do-you-install-symbolic-c-on-visual-studio-2010/13775602#13775602) answer. – dharmatech Dec 12 '12 at 07:48
2

When in doubt, add parentheses:

    if (_Str[0] < _E0 || _E0 + 9 < _Str[0])
        (_Str2 += '-'), ++_Off;

Or simply write proper C++ code:

    if (_Str[0] < _E0 || _E0 + 9 < _Str[0])
    {
        _Str2 += '-';
        ++_Off;
    }
Blindy
  • 65,249
  • 10
  • 91
  • 131
  • While I would like to avoid editing the system header ``, this solution does indeed work and SymbolicC++ 3.35 builds successfully for me (Visual C++ 2010 Express). – dharmatech Nov 26 '12 at 07:25
0

We have no idea what their operator, is doing, so this may well not be valid, but that's a weird way to do things -- the following is equivalent and less weird:

    if (_Str[0] < _E0 || _E0 + 9 < _Str[0]) {
        _Str2 += '-';
        ++_Off;
    }
Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
0

The comma operator doesn't make any sense in 90% of the cases. The solution is to hit whoever wrote that code in the head with a blunt object, then rewrite it as:

if (_Str[0] < _E0 || _E0 + 9 < _Str[0])
{
  _Off++;
  _Str2 += '-';
}
Lundin
  • 195,001
  • 40
  • 254
  • 396