diff --git a/applications/test/limits/Test-limits.C b/applications/test/limits/Test-limits.C new file mode 100644 index 0000000000..4123d475d8 --- /dev/null +++ b/applications/test/limits/Test-limits.C @@ -0,0 +1,63 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 . + +Description + Print max limits. + +\*---------------------------------------------------------------------------*/ + +#include +#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::max << nl; + Info<<"int16:" << std::numeric_limits::max() << nl; + Info<<"int32:" << pTraits::max << nl; + Info<<"int64:" << pTraits::max << nl; + Info<<"uint32:" << pTraits::max << nl; + Info<<"uint64:" << pTraits::max << nl; + + Info<< nl; + + cout<<"int16:" << std::numeric_limits::max() << nl; + cout<<"int32:" << pTraits::max << nl; + cout<<"int64:" << pTraits::max << nl; + cout<<"uint32:" << pTraits::max << nl; + cout<<"uint64:" << pTraits::max << nl; + + Info << "---\nEnd\n" << endl; + + return 0; +} + + +// ************************************************************************* // diff --git a/applications/test/machine-sizes/Make/files b/applications/test/machine-sizes/Make/files new file mode 100644 index 0000000000..15c18ac321 --- /dev/null +++ b/applications/test/machine-sizes/Make/files @@ -0,0 +1,3 @@ +Test-machine-sizes.cpp + +EXE = $(FOAM_USER_APPBIN)/Test-machine-sizes diff --git a/applications/test/machine-sizes/Make/options b/applications/test/machine-sizes/Make/options new file mode 100644 index 0000000000..18e6fe47af --- /dev/null +++ b/applications/test/machine-sizes/Make/options @@ -0,0 +1,2 @@ +/* EXE_INC = */ +/* EXE_LIBS = */ diff --git a/applications/test/machine-sizes/Test-machine-sizes.cpp b/applications/test/machine-sizes/Test-machine-sizes.cpp new file mode 100644 index 0000000000..784fcfbca8 --- /dev/null +++ b/applications/test/machine-sizes/Test-machine-sizes.cpp @@ -0,0 +1,112 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 . + +Description + Test the sizeof for basic types. Can be compiled and run without + any OpenFOAM libraries. + +\*---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include + +// Can also compile without OpenFOAM +#ifdef WM_LABEL_SIZE + #include "IOstreams.H" +#endif + +template +void print(const char* msg) +{ + std::cout<< msg << ' ' << sizeof(T) << '\n'; +} + + +#ifdef WM_LABEL_SIZE +template +void printMax(const char* msg) +{ + std::cout<< msg << ' ' << sizeof(T) + << " max " + << std::numeric_limits::max() << '\n'; + + Foam::Info<< msg << ' ' << sizeof(T) + << " max " + << long(std::numeric_limits::max()) << '\n'; +} +#endif + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + std::cout<<"machine sizes\n---\n\n"; + + print("mode_t"); + print("short"); + print("int"); + print("long"); + print("long long"); + print("ushort"); + print("uint"); + print("ulong"); + print("ulong-long"); + print("int16"); + print("int32"); + print("int64"); + print("uint16"); + print("uint32"); + print("uint64"); + print("float"); + print("double"); + print("std::string"); + print("std::string::size_type"); + + #ifdef WM_LABEL_SIZE + std::cout<<"\nmax values\n---\n\n"; + + printMax("mode_t"); + Foam::Info<< "mode_t 0777: " << mode_t(0777) << '\n'; + + printMax("short"); + printMax("int"); + printMax("long"); + printMax("ushort"); + printMax("uint"); + printMax("ulong"); + printMax("float"); + printMax("double"); + #endif + + std::cout << "\n---\nEnd\n\n"; + + return 0; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/Scalar/Scalar.H b/src/OpenFOAM/primitives/Scalar/Scalar.H index e351068785..f091f42765 100644 --- a/src/OpenFOAM/primitives/Scalar/Scalar.H +++ b/src/OpenFOAM/primitives/Scalar/Scalar.H @@ -89,13 +89,13 @@ public: // Member Functions - //- Access to the Scalar value + //- Access to the value operator Scalar() const { return p_; } - //- Access to the Scalar value + //- Access to the value operator Scalar&() { return p_; diff --git a/src/OpenFOAM/primitives/bools/bool/bool.H b/src/OpenFOAM/primitives/bools/bool/bool.H index 55ac2cfbff..9d413995f3 100644 --- a/src/OpenFOAM/primitives/bools/bool/bool.H +++ b/src/OpenFOAM/primitives/bools/bool/bool.H @@ -103,13 +103,13 @@ public: // Member Functions - //- Access to the bool value + //- Access to the value operator bool() const { return p_; } - //- Access to the bool value + //- Access to the value operator bool&() { return p_; diff --git a/src/OpenFOAM/primitives/ints/int32/int32.H b/src/OpenFOAM/primitives/ints/int32/int32.H index 497e7b8b5e..2d4910a159 100644 --- a/src/OpenFOAM/primitives/ints/int32/int32.H +++ b/src/OpenFOAM/primitives/ints/int32/int32.H @@ -107,9 +107,8 @@ inline bool read(const std::string& str, int32_t& val) Istream& operator>>(Istream& is, 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 -// for IO operator resolution. -// This problem is avoided by explicitly defining the following operators: +// 32bit OS: long is not unambiguously (int32_t | int64_t) +// - resolve explicitly for input and output #if WM_ARCH_OPTION == 32 Istream& operator>>(Istream& is, long& val); Ostream& operator<<(Ostream& os, const long val); @@ -163,13 +162,13 @@ public: // Member Functions - //- Access to the int32_t value + //- Access to the value operator int32_t() const { return p_; } - //- Access to the int value + //- Access to the value operator int32_t&() { return p_; diff --git a/src/OpenFOAM/primitives/ints/int64/int64.H b/src/OpenFOAM/primitives/ints/int64/int64.H index c6d097c437..36dce6ee04 100644 --- a/src/OpenFOAM/primitives/ints/int64/int64.H +++ b/src/OpenFOAM/primitives/ints/int64/int64.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / 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 This file is part of OpenFOAM. @@ -108,6 +108,13 @@ inline bool read(const std::string& str, int64_t& val) Istream& operator>>(Istream& is, 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 template<> class pTraits @@ -155,13 +162,13 @@ public: // Member Functions - //- Access to the int64_t value + //- Access to the value operator int64_t() const { return p_; } - //- Access to the int value + //- Access to the value operator int64_t&() { return p_; diff --git a/src/OpenFOAM/primitives/ints/int64/int64IO.C b/src/OpenFOAM/primitives/ints/int64/int64IO.C index 1a2ad639e3..bb0c08e1e0 100644 --- a/src/OpenFOAM/primitives/ints/int64/int64IO.C +++ b/src/OpenFOAM/primitives/ints/int64/int64IO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -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 + + // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/ints/uint32/uint32.H b/src/OpenFOAM/primitives/ints/uint32/uint32.H index 8841d878f7..94e3c13598 100644 --- a/src/OpenFOAM/primitives/ints/uint32/uint32.H +++ b/src/OpenFOAM/primitives/ints/uint32/uint32.H @@ -154,13 +154,13 @@ public: // Member Functions - //- Access to the uint32_t value + //- Access to the value operator uint32_t() const { return p_; } - //- Access to the uint32_t value + //- Access to the value operator uint32_t&() { return p_; diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64.H b/src/OpenFOAM/primitives/ints/uint64/uint64.H index 7c63a695c3..8bc75023f1 100644 --- a/src/OpenFOAM/primitives/ints/uint64/uint64.H +++ b/src/OpenFOAM/primitives/ints/uint64/uint64.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / 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 This file is part of OpenFOAM. @@ -107,6 +107,13 @@ inline bool read(const std::string& str, uint64_t& val) Istream& operator>>(Istream& is, 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 template<> class pTraits @@ -154,13 +161,13 @@ public: // Member Functions - //- Access to the uint64_t value + //- Access to the value operator uint64_t() const { return p_; } - //- Access to the uint64_t value + //- Access to the value operator uint64_t&() { return p_; diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64IO.C b/src/OpenFOAM/primitives/ints/uint64/uint64IO.C index b73e90e771..1fb0f5adaf 100644 --- a/src/OpenFOAM/primitives/ints/uint64/uint64IO.C +++ b/src/OpenFOAM/primitives/ints/uint64/uint64IO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -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 + + // ************************************************************************* //