Skip to content

The macro name is the same as the std member #1591

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

Closed
XY-ShadowK opened this issue Dec 29, 2024 · 8 comments
Closed

The macro name is the same as the std member #1591

XY-ShadowK opened this issue Dec 29, 2024 · 8 comments
Assignees

Comments

@XY-ShadowK
Copy link

Describe the bug

#if !defined(isfinite)
#include <float.h>
#define isfinite _finite
#endif

The macro name isfinite is the same as std::isfinite, which can cause compiler to incorrectly replace std::isfinite to std::_finite.

To Reproduce
Just use std::isfinite after the inclusion of jsoncpp.cpp.

Expected behavior
A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • OS: Windows 10 22H2 x64

Additional context
Please use std::isfinite to check values, or use _isfinite directly or use other macro name to circumvent std member names.

@BillyDonahue BillyDonahue self-assigned this Jan 9, 2025
@BillyDonahue
Copy link
Contributor

I agree that's messed up to use a colliding name. We could just use some other name.

Just use std::isfinite after the inclusion of jsoncpp.cpp.

But why would you be including a .cpp file?
The macros are safe in the json_writer.cpp file if used as intended.

BillyDonahue added a commit that referenced this issue Jan 9, 2025
We assume C++11 elsewhere so all pre-11 #ifdef branches are dead code at this point.
Fixes issue #1591 because we can just use std::isfinite.
BillyDonahue added a commit that referenced this issue Jan 9, 2025
We already assume C++11 elsewhere, so all pre-11 `#ifdef` branches are
dead code at this point. Fixes issue #1591 because we can just use
`std::isfinite` etc.

assume C++11 in json_reader.cpp as well

apply clang-format
@XY-ShadowK
Copy link
Author

But why would you be including a .cpp file? The macros are safe in the json_writer.cpp file if used as intended.

I followed the guidelines of Amalgamated- (Possibly-outdated) to import jsoncpp.
If I want to compile a cross-platform project, can I import it this way and build with my own project? Or do I need to follow the instructions of Build-with-VS-2019-on-Windows and Building to build and import separately?

@BillyDonahue
Copy link
Contributor

BillyDonahue commented Jan 9, 2025

I think you misunderstood the guidelines.
The amalgamation script produces a .h and a .cpp file.

You add these to your project.
This means you add the single .cpp file to your Makefile or whatever you're using.
It doesn't mean that you #include it into your own files. Building jsoncpp still a separate compilation step.

@XY-ShadowK
Copy link
Author

As below?
So can it be built cross-paltform with my project?

cl src/mySrc.cpp jsoncpp-1.9.5/dist/jsoncpp.cpp /I jsoncpp-1.9.5/dist
g++ src/mySrc.cpp jsoncpp-1.9.5/dist/jsoncpp.cpp -I jsoncpp-1.9.5/dist

@BillyDonahue
Copy link
Contributor

i don't think so. That's not a Makefile.
You need to pick a build system like make or CMake or something and do what they do

@XY-ShadowK
Copy link
Author

XY-ShadowK commented Jan 9, 2025

i don't think so. That's not a Makefile.

I know, it is just for debugging at development time, when you haven't added a task to the new source file.
I want to know whether it need more conditional judgment or environment variable setting to build cross-platform.

if(WIN32)
    set(CMAKE_CXX_COMPILER "MSVC")
    set(MIN_SDK_VERSION "10.0.19041")
    set(MIN_MSVC_VERSION "1920")
elseif(UNIX)
    set(CMAKE_CXX_COMPILER "g++")
endif()

@BillyDonahue
Copy link
Contributor

i don't know those details. sorry. But yeah if all you have is a shell script with one g++ command line then just add the amalgamated jsoncpp.cpp to that.

But we're outside of jsoncpp issues here.

@XY-ShadowK
Copy link
Author

XY-ShadowK commented Jan 9, 2025

Thanks for your patience.
You're the gentlest developer I've ever seen on github.

baylesj pushed a commit that referenced this issue Jan 10, 2025
* Assume C++11

We already assume C++11 elsewhere, so all pre-11 `#ifdef` branches are
dead code at this point. Fixes issue #1591 because we can just use
`std::isfinite` etc.

assume C++11 in json_reader.cpp as well

apply clang-format

* valueToString: simplify lookup of special float name
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