-
Notifications
You must be signed in to change notification settings - Fork 290
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
FIX: build warning - cast from pointer to integer of different size #110
Conversation
While libm can be linked on generating final executable, it's still preferred to link it against the library itself to better represent the dependency hierarchy.
Added support for MSVC and (rather coincidentally) C++98 by replacing the decltype keyword and removing the corresponding preprocessor checks.
To prevent warnings in modern compilers
Example (starting in the source directory): $ mkdir build $ cd build $ ../configure $ make Make complains: ar rcs libjsonparser.a json.o ar: json.o: No such file or directory make: *** [Makefile:29: libjsonparser.a] Error 1
json.h: <inttypes.h> → <stdint.h> int64_t is defined in <stdint.h>, no need for the full <inttypes.h> json.h: <stdlib.h> → <stddef.h> <stddef.h> is enough to define size_t json.c: <stdlib.h> Now that <stdlib.h> has been removed from json.h, add it to json.c for malloc()/calloc() and free()
Thanks! Unfortunately this may be more complicated than originally assumed. |
Note that the library already includes header
and
Both headers are C99, not ANSI-C. But yes, it's quite possible to define |
Note that function
Eventually you shall cast to This tells me something's wrong here. I might be missing something, but why would the size of the allocation be a multiple of the value of a pointer?
It should be a multiple of the size of a pointer! For example, for
|
It's because there is something hacky in there. In the first pass, the
Weirdly it casts it to a json_char* to add to it rather than an unsigned long or a size_t. I guess that's just a mistake. Then, in the second pass, it interprets it as an unsigned long to allocate enough space for all of the names together, in the fragment of code you found:
The explicit way to describe what is happening would be with a union:
I guess I didn't do that because in ANSI C unions have to be named, so So to fix this I think the options would be:
I think option 3 is the cleanest? But any suggestions welcome. |
Thanks for the explanation. It's probably difficult to totally remove the warning when retrieving an integer from a larger pointer, unless a union is used to store the different types.
|
…whitespaces Get rid of trailing whitespaces
…signed_int cur_line and cur_col are unsigned
Added fall through markers
example: fix typo
Remove dependency on decltype in C++ API
Add LDFLAGS support and missing lm option
@DimitriPapadopoulos I'll be away from work for a week, so I won't be able to answer before the 6th of September |
The warning only occurs when compiling for 64-bit architectures (e.g. x86_64 or ARM64) when warning C4311: 'type cast': pointer truncation from 'void *' to 'unsigned long' To get a similar warning for clang or gcc you would have to target Windows 64-bit as that is what causes |
I confirm what @LB-- said: this warning occurs when targeting 64-bit Windows. |
Thank you @ChromaticIsobar. I won't have time to cross-compile to test that in the near future, could you perhaps check whether #133 helps in your case? |
It does. It took a little because #133 caused |
Do I get it right that |
And actually this change has not removed |
That's correct Before #133 I included So, I had to add the |
Right, while you should always include |
I totally agree |
Do you want me to close this PR in favour of #133 ? |
File test.py is executable in Git, yet does not start with "#!".
Forgot to merge this with the others...
My plan currently is this:
The goal is to at least silence the warning for most people ASAP before engaging in a more drastic change for the sake of silencing the warning in C89. Any objections to this plan? |
That's the standard over all the C standard library.
Either it has been defined explictly, or we attempt to calculate it using the method reverted by fcfa748. See discussion in json-parser#84 and json-parser#102.
Fix valid-0013.json added by fab533e (json-parser#125)
It looks like a bad idea to compare apply to a double operators ++ and --, or to compare to integers.
Oops. Well, the PR is a bit of a mess now, but the relevant changes can be seen in b10ff61 - I guess now it just handles the edge case where |
See PR #92