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
Use more stdint.h types and document disabling stdint.h #149
Conversation
I am still unsure whether it is a good choice to make this change. It can be openly discussed. But if it is to be changed, there will be a lot of places to be changed, including |
I'm happy to discuss it. Thanks for pointing out the other places. I'll do those within the next few days, as I have time. |
First of all, I agree that RapidJSON currently assumes I suggested to use I still don't see the real benefit in using |
Oh, and I should add, that this change may even lead to ambiguity problems, depending on the actual definition of void foo(bool) {}
void foo(long) {}
// foo(1) -> foo(int) -> ambiguous! Therefore, I would rather not change the current types. Still, adding a static assert to catch failing assumptions on the |
@pah I will try to understand and address your concerns.
|
In Google's C++ style guide, there are some suggestions which we can discuss and consider.
|
@miloyip Good idea to look at other style guides. I think those guidelines make sense in general. For types that are not user-facing and/or explicitly sized – e.g. in loops – using While we're looking at Google code, protobuf uses |
And revise the documentation.
I have updated the code to change the types wherever I thought was reasonable. Your feedback is appreciated. |
I'm just curious about the status on this. Do you want to discuss it or think it over more? Is there something I should change? |
I still think that this is an unreasonable change. Potentially having to cast(!) an If we want to add something like this, we should probably rather use something like My 2¢. |
As I mentioned above, I think the benefits are clear. The usage of Also, I noticed Anyway, I guess we'll have to agree to disagree. 😄
I'm not against this, though I don't really see the need for it. But I'm happy to go along. Do you want each of them to be separately overridable?
Definitely reasonable. @miloyip Your thoughts? |
Yes, but not as part of an overload set with
Agreed. 😺
It's probably fine to have a single switch for both (or rather all four) types. As mentioned before: RapidJSON's assumption on And I just don't want to break user code due to the (potentially) changing overload set. At least, we should then provide a way to keep the old behaviour by allowing an override of the new "default" type selections. But I guess we should wait for @miloyip's position on this topic. |
I against the change. The interface should use standard types, and if the implementation relies on bitwise operations we can choose extended integer types. If rapidjson's implementation assume |
Does using |
@gnzlbg: JSON is a text format, so it can be safely shared across platforms. |
@pah but can you accidentally write a 64bit int as ASCII number and then try to read it into a 32bit int in another platform because in one platform int = 64bit and in another int = 32bit? |
After parsing a JSON document, you need to validate the inputs anyway. And |
So does that mean that it is not possible to write 64bit ints? |
Of course you can read/write 64-bit integers, there's |
Thank @spl very much for offering this PR. After quite a lot of discussion, I think it is quite a style issue rather than improving in practical situations. As it comes to an official release now, I do not want to potentially break the interface. I think this can be reconsidered for a next major version (which may change the API) in future. |
Summary
RAPIDJSON_NO_INT64DEFINE
toRAPIDJSON_NO_STDINT
and revise documentation to address @pah's concern about unconditionally usingint32_t
/uint32_t
.As I discussed in #145, I think this change improves several things:
RAPIDJSON_NO_STDINT
more accurately describes its purpose thanRAPIDJSON_NO_INT64DEFINE
did. It disables the#include <stdint.h>
and doesn't only disable the definition ofint64_t
/uint64_t
. Of course, this is more significant with the usage ofint32_t
/uint32_t
.@pah had the concern that the type definition
int32_t
implied the implementation type would be restricted to 32 bits on a 64-bit system. I'm certain all 64-bit systems will use the most efficient implementation type forint32_t
. To check, I looked atstdint.h
on Mac OS X and Linux as well asmsinttypes/stdint.h
: all of them useint
.