Skip to content
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

For better portability, stop using the type long #159

Open
ddeclerck opened this issue Jul 30, 2024 · 2 comments
Open

For better portability, stop using the type long #159

ddeclerck opened this issue Jul 30, 2024 · 2 comments

Comments

@ddeclerck
Copy link
Contributor

ddeclerck commented Jul 30, 2024

A potential source of bugs - and one of the reasons the MSVC debug CIs hangs / displays a runtime checker popup - is the use of the long type , whose size differs in 64-bit mode on MSVC (4 bytes) vs "rest of the world" compilers (8 bytes).
(nitpicker's corner: okay, there might be a few other exceptions)

As an example, the test FUNCTION RANDOM fails here (intrinsic.c:cob_intr_random) :

seed = get_seconds_past_midnight () * (long)COB_MODULE_PTR;

Indeed, a 64-bit pointer won't fit in a 32-bit long, and the MSVC runtime checker will complain.

Wherever the size matters, I'd suggest using the C99 fixed width integer types (u)int64_t - providing a custom definition when missing. Or, we could just use cob_u64_t / cob_s64_t.
(nitpicker's corner bis: yeah, for a pointer the proper cast would be to (u)intptr_t, not (u)int64_t)

Thoughts ?

@GitMensch
Copy link
Collaborator

This is the wrong place for this "feature request" - please create that upstream.

Obviously:

  • the calls to library functions outside of GnuCOBOL cannot be changed
  • API (= external visible) changes may only be done in GC4

C99 types are nice - and should be postponed to GC4 with a fallback possibly provided by gnulib.

For the specific sample: a cast / bitwise truncation to cob_u32_t would be fine as well.

@ddeclerck
Copy link
Contributor Author

Indeed, I opened that on SF => https://sourceforge.net/p/gnucobol/feature-requests/476/.

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