Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence warning in Visual Studio 2010 when using zdouble #10

Closed
Loutjie opened this issue Aug 6, 2015 · 6 comments
Closed

Silence warning in Visual Studio 2010 when using zdouble #10

Loutjie opened this issue Aug 6, 2015 · 6 comments

Comments

@Loutjie
Copy link

Loutjie commented Aug 6, 2015

Visual Studio 2010 generates warning when using zdouble in place of double. To silence then, the following constructors are added:

/// Constructor from size_t
zdouble(const size_t& ulong)
: dbl_((double)ulong)
{ }
/// Constructor from int
zdouble(const int& signint)
: dbl_((double)signint)
{ }

@bradbell
Copy link
Contributor

I now have visual studio 2013 up and running without without warnings, expect for the fact that asctime and gmtime are not thread safe (which I have decided to leave for the time being).

Would you please provide a simple example that results in the warnings you intend to fix here and (so I can add it to the CppAD tests to make sure that the fix works).

@Loutjie
Copy link
Author

Loutjie commented Sep 23, 2015

The warning appear at every call to ‘Forward(0, x)’;

Example:

     std::vector<CppAD::AD<CppAD::zdouble>> vdX(1);

     std::vector<CppAD::AD<CppAD::zdouble>> vdY(1);

     CppAD::ADFun<CppAD::zdouble> Function;

     std::vector<CppAD::zdouble> vdX2(1);

     std::vector<CppAD::zdouble> vdY2(1);

     vdX[0] = 10.0;

     Independent(vdX);

     vdY[0] = vdX[0]*2.0;

     Function.Dependent(vdX, vdY);

     vdX2[0] = 20.0;

     vdY2 = Function.Forward(0, vdX2); // Generates warnings during compilation

If I add this template constructor

template
/// Constructor from double
zdouble(const Base& value)
: dbl_((double)value)
{ }

And remove the double constructor

                /// Constructor from double
     /*zdouble(const double& dbl)
     : dbl_(dbl)
     { }*/

Then the warnings are silenced.

Kind regards

Loutjie

From: Brad Bell [mailto:notifications@github.com]
Sent: 2015 September 22 07:36 PM
To: coin-or/CppAD
Cc: Loutjie
Subject: Re: [CppAD] Silence warning in Visual Studio 2010 when using zdouble (#10)

I now have visual studio 2013 up and running without without warnings, expect for the fact that asctime and gmtime are not thread safe (which I have decided to leave for the time being).

Would you please provide a simple example that results in the warnings you intend to fix here and (so I can add it to the CppAD tests to make sure that the fix works).


Reply to this email directly or view it on GitHub #10 (comment) . https://github.com/notifications/beacon/AM7EHxXoOUkgr7kYkJdDJIl1MHaHPDNSks5o0YjogaJpZM4FmpYj.gif

@Loutjie
Copy link
Author

Loutjie commented Sep 23, 2015

We compile at Warning Level 4.

From: Brad Bell [mailto:notifications@github.com]
Sent: 2015 September 22 07:36 PM
To: coin-or/CppAD
Cc: Loutjie
Subject: Re: [CppAD] Silence warning in Visual Studio 2010 when using zdouble (#10)

I now have visual studio 2013 up and running without without warnings, expect for the fact that asctime and gmtime are not thread safe (which I have decided to leave for the time being).

Would you please provide a simple example that results in the warnings you intend to fix here and (so I can add it to the CppAD tests to make sure that the fix works).


Reply to this email directly or view it on GitHub #10 (comment) . https://github.com/notifications/beacon/AM7EHxXoOUkgr7kYkJdDJIl1MHaHPDNSks5o0YjogaJpZM4FmpYj.gif

@bradbell
Copy link
Contributor

Warning level 4
https://msdn.microsoft.com/en-us/library/thxezb7y.aspx
is the key. It is generating lots more warnings in my tests. I will look
at them.

Brad.

On 9/22/2015 10:15 PM, Loutjie wrote:

We compile at Warning Level 4.

From: Brad Bell [mailto:notifications@github.com]
Sent: 2015 September 22 07:36 PM
To: coin-or/CppAD
Cc: Loutjie
Subject: Re: [CppAD] Silence warning in Visual Studio 2010 when using
zdouble (#10)

I now have visual studio 2013 up and running without without warnings,
expect for the fact that asctime and gmtime are not thread safe (which
I have decided to leave for the time being).

Would you please provide a simple example that results in the warnings
you intend to fix here and (so I can add it to the CppAD tests to make
sure that the fix works).


Reply to this email directly or view it on GitHub
#10 (comment) .
https://github.com/notifications/beacon/AM7EHxXoOUkgr7kYkJdDJIl1MHaHPDNSks5o0YjogaJpZM4FmpYj.gif


Reply to this email directly or view it on GitHub
#10 (comment).

@bradbell
Copy link
Contributor

On 9/22/2015 10:14 PM, Loutjie wrote:

The warning appear at every call to ‘Forward(0, x)’;

... snip ...

I have made some recent changes and now get no warning (with Visual
Studio 2013) with the following steps in a Windows CMD window
mkdir build
cd build
cmake -G "NMake Makefiles" -D cppad_cxx_flags="/W4" ..
nmake check_example
see
5787b4a

Note that this includes no warnings when compiling the file
https://github.com/coin-or/CppAD/blob/master/example/zdouble.cpp
and that files has order zero forward mode computations (using zdouble)
in it; see the code
z = g.Forward(0, x);
and consider the case where Base = zdouble.

In addition, I have tried replacing zdouble.cpp by the following (at
your suggestion) and still get no warning when executing 'nmake
check_example'.

include <cppad/cppad.hpp>

bool zdouble(void)
{ bool ok = true;
using std::cout;
//
std::vectorCppAD::ADCppAD::zdouble vdX(1);
std::vectorCppAD::ADCppAD::zdouble vdY(1);
CppAD::ADFunCppAD::zdouble Function;
std::vectorCppAD::zdouble vdX2(1);
std::vectorCppAD::zdouble vdY2(1);
vdX[0] = 10.0;
Independent(vdX);
vdY[0] = vdX[0]*2.0;
Function.Dependent(vdX, vdY);
vdX2[0] = 20.0;
vdY2 = Function.Forward(0, vdX2); // Generates warnings during
compilation
//
return ok;
}
~

@bradbell
Copy link
Contributor

bradbell commented Oct 6, 2015

If one uses the Visual Studio 2013 and the windows download, extraction, and testing instructions on
http://www.coin-or.org/CppAD/Doc/download.htm#Compressed%20Archives.Windows%20File%20Extraction%20and%20Testing
the only warnings are

  1. C4996: gmtime and asctime my be unsafe.
  2. LNK4044: unrecognized option '/openmp'; ignored
    The functions asctime and gmtime are called when onlly one thread is active and there does not seem to be a standard way to get a thread safe version of these functions. The option /openmp is generated by cmake and is not valid for Visual Studio 2013 (but I think it works for 2015)

Note that the CppAD source code now suppresses the warnings

  1. C4100 unreferenced formal parameter
  2. C4127 conditional expression is constant
    This is mentioned under the heading 09-24 on
    http://www.coin-or.org/CppAD/Doc/whats_new_15.htm#09-24
    CppAD uses the same signature for similar routines that in some cases do not use formal parameters. In addition, it has asserts for expressions that are constant.

@bradbell bradbell closed this as completed Oct 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants