Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-12-05 12:01:45


I've finally made time - a milli-fortnight or so ;-) to try this out.

I've got your demo to run using MSVC 7.1.

Using 'strict' mode I found some wrinklettes:

1 Most files do not end with a newline, after the last line, for example:

#endif // MCS_SI_UNITS_HPP

The picky C++ Standard requires this (or it fails to compile with level 4
(highest warning level). Trivial to fix, but annoying for pedants.

2 There are zillions of signed/unsigned mismatches which can be 'cured' by

      replacing
 for (int i=0; i<avec.size(); ++i)
by
        for (std::size_t i = 0; i != avec.size(); ++i)

in a few places.

3 I believe it is more helpful to understand the demo if the units are specified
thus

using mcs::units::si::_newton;
using mcs::units::si::_meter;
using mcs::units::si::_meters; // An alias.

(Even if one might well avoid this with

   using namespace mcs::units::si;

in 'real life').

4 I am a little alarmed at the effect of compile time (30 s on my semi-senile
machine), but Intel and AMD are no doubt working on this for us.

5 There are a handful of warning that an assignment operator could not be
generated. The MS advice on this is:

"To avoid this warning, specify a user-defined assignment operator for the
class.

The compiler will also generate an assignment operator function for a class that
does not define one. This assignment operator is simply a member wise copy of
the data members of an object. Because const data items cannot be modified after
initialization, if the class contains a const item, the default assignment
operator would not work.

For example, the following code generates C4512:

// C4512.cpp
// compile with: /EHsc /W4
#include <iostream>
using namespace std;
class base
{
   const int a;
public:
   base(int val = 0) : a(val)
   {
   }
   int get_a(void)
   {
   return a;
   }
}; // C4512

int main()
{
   base first;
   base second(5);

   cout << "First = " << first.get_a() << endl;
   cout << "Second = " << second.get_a() << endl;
}
You can resolve the C4512 warning for this code in one of three ways:

Explicitly define an assignment operator for the class.
Remove const from the data item in the class.
Use the #pragma warning statement. "

I chose the latter easy option.

# pragma warning(disable: 4512) // assignment operator could not be generated

Gurus views on this?

And also decided that these warnings were not helpful.

# pragma warning(disable: 4100) // unreferenced formal parameter
(I couldn't even see what was unreferenced ).

# pragma warning(disable: 4127) // conditional expression is constant
And this is entirely expected.

(Do we need a Boost list of unhelpful warnings?)

Is there a Boost 'Standard' way to do document unhelpful warnings like this?
Perhaps:

#ifdef _MSC_VER
# pragma warning(disable: 4702) // unreachable code
# pragma warning(disable: 4127) // conditional expression is constant
# pragma warning(disable: 4512) // assignment operator could not be generated
# pragma warning(disable: 4100) // unreferenced formal parameter
#endif

#else other compilers?

(I even had to include

# pragma warning(disable: 4702) // unreachable code
// to avoid warnings in insert_n in STL vector!

        this->_Alval.deallocate(_Newvec, _Capacity);
        _RERAISE;
        _CATCH_END
but have ignored it).

6 I note you are using your 'own' rational. Is there a reason you are not
using the Boost one?

7 The test_dimensional_analysis produced:

> was unexpected at this time.

> was unexpected at this time.

> was unexpected at this time.

> was unexpected at this time.

> was unexpected at this time.

> was unexpected at this time.

> was unexpected at this time.

'c++filt' is not recognized as an internal or external command,
operable program or batch file.

But I have yet to even understand what it is expected to do!

Overall, it looks most promising to me, but I want to try to use it for real a
bit more.

Some documentation would be very helpful.

Paul

Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
mailto:pbristow_at_[hidden]

| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]]On Behalf Of Matthias Schabel
| Sent: Monday, November 17, 2003 9:53 PM
| To: boost_at_[hidden]
| Subject: [boost] new compile-time dimensional analysis and unit library

| files section : http://groups.yahoo.com/group/boost/files/YANL.zip
|
| Matthias
|
|


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk