Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use existing C89 header files #127

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

Merged
merged 1 commit into from
Oct 30, 2021
Merged

Conversation

DimitriPapadopoulos
Copy link
Contributor

No description provided.

@LB--
Copy link
Member

LB-- commented Aug 23, 2021

It looks like the compiler codegen is the same between both the old and new code, so this is mainly a question of what makes the code more maintainable. In a C++ codebase I would use decltype within std::numeric_limits<>::max to perform this task, but we don't have that luxury here. If the types of those variables in the state structure were to change, the original code would work without changes, where as your proposed new code would have to be altered. This seems less maintainable to me, since if someone forgets to change those lines, it will silently have the wrong behavior. Is there a specific reason for changing this code? As far as I understand, unsigned types are always represented in memory the same way on all platforms.

@jamesamcl
Copy link
Collaborator

I actually think *_max can be removed from the state completely and the constants from limits.h can be used directly instead? I guess I didn't know they existed in C89.

@LB--
Copy link
Member

LB-- commented Aug 23, 2021

Ah, good point, I should have looked more at where those values where actually used in the code. That seems to be a better solution indeed.

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented Aug 23, 2021

The specific reason is that UNIT_MAX and ULONG_MAX are already defined by the standard library, they're used everywhere in C code, and programmers are used to using these variables.

No real reason, in short :-)

@DimitriPapadopoulos
Copy link
Contributor Author

Yes, these global constants could be used instead and uint_max/ulong_max removed from state. I had that in mind, but I thought you might want them to avoid using UINT_MAX - 8/ULONG_MAX - 8 everywhere.

@jamesamcl
Copy link
Collaborator

Even with -8 they are still constant, so would be better to store them as const rather than in the state.

@DimitriPapadopoulos
Copy link
Contributor Author

Is static const int = ... C89? I'll try...

@DimitriPapadopoulos DimitriPapadopoulos force-pushed the uint_max branch 2 times, most recently from e89515c to 44f2a14 Compare August 23, 2021 21:01
@DimitriPapadopoulos
Copy link
Contributor Author

I've ended up changing to UINT_MAX - 8 and ULONG_MAX - 8 - much simpler and reminds of the - 8.

@LB-- LB-- added this to the v1.1.1 milestone Sep 3, 2021
This was referenced Sep 3, 2021
@LB-- LB-- merged commit bb4135c into json-parser:master Oct 30, 2021
@DimitriPapadopoulos DimitriPapadopoulos deleted the uint_max branch October 31, 2021 08:01
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

Successfully merging this pull request may close these issues.

3 participants