Skip to content
Snippets Groups Projects
Commit 672f0574 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

COMP: resolve signed/unsigned long ambiguity on Darwin

parent 29c020f5
No related branches found
No related tags found
No related merge requests found
Showing with 230 additions and 19 deletions
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Print max limits.
\*---------------------------------------------------------------------------*/
#include <limits>
#include "int.H"
#include "uint.H"
#include "string.H"
#include "IOstreams.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
//NONE Info<<"int16:" << pTraits<int16_t>::max << nl;
Info<<"int16:" << std::numeric_limits<int16_t>::max() << nl;
Info<<"int32:" << pTraits<int32_t>::max << nl;
Info<<"int64:" << pTraits<int64_t>::max << nl;
Info<<"uint32:" << pTraits<uint32_t>::max << nl;
Info<<"uint64:" << pTraits<uint64_t>::max << nl;
Info<< nl;
cout<<"int16:" << std::numeric_limits<int16_t>::max() << nl;
cout<<"int32:" << pTraits<int32_t>::max << nl;
cout<<"int64:" << pTraits<int64_t>::max << nl;
cout<<"uint32:" << pTraits<uint32_t>::max << nl;
cout<<"uint64:" << pTraits<uint64_t>::max << nl;
Info << "---\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //
Test-machine-sizes.cpp
EXE = $(FOAM_USER_APPBIN)/Test-machine-sizes
/* EXE_INC = */
/* EXE_LIBS = */
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Test the sizeof for basic types. Can be compiled and run without
any OpenFOAM libraries.
\*---------------------------------------------------------------------------*/
#include <cstdint>
#include <climits>
#include <cstdlib>
#include <limits>
#include <iostream>
// Can also compile without OpenFOAM
#ifdef WM_LABEL_SIZE
#include "IOstreams.H"
#endif
template<class T>
void print(const char* msg)
{
std::cout<< msg << ' ' << sizeof(T) << '\n';
}
#ifdef WM_LABEL_SIZE
template<class T>
void printMax(const char* msg)
{
std::cout<< msg << ' ' << sizeof(T)
<< " max "
<< std::numeric_limits<T>::max() << '\n';
Foam::Info<< msg << ' ' << sizeof(T)
<< " max "
<< long(std::numeric_limits<T>::max()) << '\n';
}
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
std::cout<<"machine sizes\n---\n\n";
print<mode_t>("mode_t");
print<short>("short");
print<int>("int");
print<long>("long");
print<long long>("long long");
print<unsigned short>("ushort");
print<unsigned int>("uint");
print<unsigned long>("ulong");
print<unsigned long long>("ulong-long");
print<int16_t>("int16");
print<int32_t>("int32");
print<int64_t>("int64");
print<uint16_t>("uint16");
print<uint32_t>("uint32");
print<uint64_t>("uint64");
print<float>("float");
print<double>("double");
print<std::string>("std::string");
print<std::string::size_type>("std::string::size_type");
#ifdef WM_LABEL_SIZE
std::cout<<"\nmax values\n---\n\n";
printMax<mode_t>("mode_t");
Foam::Info<< "mode_t 0777: " << mode_t(0777) << '\n';
printMax<short>("short");
printMax<int>("int");
printMax<long>("long");
printMax<unsigned short>("ushort");
printMax<unsigned int>("uint");
printMax<unsigned long>("ulong");
printMax<float>("float");
printMax<double>("double");
#endif
std::cout << "\n---\nEnd\n\n";
return 0;
}
// ************************************************************************* //
...@@ -89,13 +89,13 @@ public: ...@@ -89,13 +89,13 @@ public:
// Member Functions // Member Functions
//- Access to the Scalar value //- Access to the value
operator Scalar() const operator Scalar() const
{ {
return p_; return p_;
} }
//- Access to the Scalar value //- Access to the value
operator Scalar&() operator Scalar&()
{ {
return p_; return p_;
......
...@@ -103,13 +103,13 @@ public: ...@@ -103,13 +103,13 @@ public:
// Member Functions // Member Functions
//- Access to the bool value //- Access to the value
operator bool() const operator bool() const
{ {
return p_; return p_;
} }
//- Access to the bool value //- Access to the value
operator bool&() operator bool&()
{ {
return p_; return p_;
......
...@@ -107,9 +107,8 @@ inline bool read(const std::string& str, int32_t& val) ...@@ -107,9 +107,8 @@ inline bool read(const std::string& str, int32_t& val)
Istream& operator>>(Istream& is, int32_t& val); Istream& operator>>(Istream& is, int32_t& val);
Ostream& operator<<(Ostream& os, const int32_t val); Ostream& operator<<(Ostream& os, const int32_t val);
// On 32bit OSs long is not unambiguously int32_t (or int64_t) causing problems // 32bit OS: long is not unambiguously (int32_t | int64_t)
// for IO operator resolution. // - resolve explicitly for input and output
// This problem is avoided by explicitly defining the following operators:
#if WM_ARCH_OPTION == 32 #if WM_ARCH_OPTION == 32
Istream& operator>>(Istream& is, long& val); Istream& operator>>(Istream& is, long& val);
Ostream& operator<<(Ostream& os, const long val); Ostream& operator<<(Ostream& os, const long val);
...@@ -163,13 +162,13 @@ public: ...@@ -163,13 +162,13 @@ public:
// Member Functions // Member Functions
//- Access to the int32_t value //- Access to the value
operator int32_t() const operator int32_t() const
{ {
return p_; return p_;
} }
//- Access to the int value //- Access to the value
operator int32_t&() operator int32_t&()
{ {
return p_; return p_;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -108,6 +108,13 @@ inline bool read(const std::string& str, int64_t& val) ...@@ -108,6 +108,13 @@ inline bool read(const std::string& str, int64_t& val)
Istream& operator>>(Istream& is, int64_t& val); Istream& operator>>(Istream& is, int64_t& val);
Ostream& operator<<(Ostream& os, const int64_t val); Ostream& operator<<(Ostream& os, const int64_t val);
// On Darwin: long is not unambiguously (int32_t | int64_t)
// - explicitly resolve for output
#if WM_ARCH_OPTION == 64 && defined(darwin)
Ostream& operator<<(Ostream& os, const long val);
#endif
//- Template specialization for pTraits<int64_t> //- Template specialization for pTraits<int64_t>
template<> template<>
class pTraits<int64_t> class pTraits<int64_t>
...@@ -155,13 +162,13 @@ public: ...@@ -155,13 +162,13 @@ public:
// Member Functions // Member Functions
//- Access to the int64_t value //- Access to the value
operator int64_t() const operator int64_t() const
{ {
return p_; return p_;
} }
//- Access to the int value //- Access to the value
operator int64_t&() operator int64_t&()
{ {
return p_; return p_;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -120,4 +120,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const int64_t val) ...@@ -120,4 +120,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const int64_t val)
} }
#if WM_ARCH_OPTION == 64 && defined(darwin)
Foam::Ostream& Foam::operator<<(Ostream& os, const long val)
{
os << int64_t(val);
return os;
}
#endif
// ************************************************************************* // // ************************************************************************* //
...@@ -154,13 +154,13 @@ public: ...@@ -154,13 +154,13 @@ public:
// Member Functions // Member Functions
//- Access to the uint32_t value //- Access to the value
operator uint32_t() const operator uint32_t() const
{ {
return p_; return p_;
} }
//- Access to the uint32_t value //- Access to the value
operator uint32_t&() operator uint32_t&()
{ {
return p_; return p_;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -107,6 +107,13 @@ inline bool read(const std::string& str, uint64_t& val) ...@@ -107,6 +107,13 @@ inline bool read(const std::string& str, uint64_t& val)
Istream& operator>>(Istream& is, uint64_t& val); Istream& operator>>(Istream& is, uint64_t& val);
Ostream& operator<<(Ostream& os, const uint64_t val); Ostream& operator<<(Ostream& os, const uint64_t val);
// On Darwin: unsigned long is not unambiguously (uint32_t | uint64_t)
// - explicitly resolve for output
#if WM_ARCH_OPTION == 64 && defined(darwin)
Ostream& operator<<(Ostream& os, const unsigned long val);
#endif
//- Template specialization for pTraits<uint64_t> //- Template specialization for pTraits<uint64_t>
template<> template<>
class pTraits<uint64_t> class pTraits<uint64_t>
...@@ -154,13 +161,13 @@ public: ...@@ -154,13 +161,13 @@ public:
// Member Functions // Member Functions
//- Access to the uint64_t value //- Access to the value
operator uint64_t() const operator uint64_t() const
{ {
return p_; return p_;
} }
//- Access to the uint64_t value //- Access to the value
operator uint64_t&() operator uint64_t&()
{ {
return p_; return p_;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -119,4 +119,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const uint64_t val) ...@@ -119,4 +119,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const uint64_t val)
} }
#if WM_ARCH_OPTION == 64 && defined(darwin)
Foam::Ostream& Foam::operator<<(Ostream& os, const unsigned long val)
{
os << uint64_t(val);
return os;
}
#endif
// ************************************************************************* // // ************************************************************************* //
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment