-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Aid compatibility with older Microsoft C compilers #1176
Conversation
1e0f9c0
to
643752d
Compare
I'm confused, why don't you simply compile you C code with MSVC to check that it's compatible ? |
I'll look into what I've done incorrectly with the msvc32 port later @oandrieu - that forces me or anyone else to be developing my code using msvc or to correct later on (in CI, whatever) after I've fixed other bugs vs having GCC tell me about accidentally C89+isms at the same as my actual bugs. It's also a problem if:
|
50556c3
to
fb070dc
Compare
msvc32 should be fixed - a little more extra care was needed to ensure that @stedolan, in addition to helpfully confirming that there shouldn't be semantic worry because |
@dra27 In my experience, the most common incompatibility between old MSVC and C99 is mixing declaration and statements, wouldn't the Another possibility would be to leave #if defined (__GNUC__) && (__STDC_VERSION__ < 199901L)
# define inline __inline__
#endif |
The ISO C 1999 standard is old enough to vote in many countries. It makes me sad that we still cannot write the OCaml runtime system in proper C99. This said, I'm not against the approach proposed here. But I'd rather not use So, I'd rather have a macro, say Alternatively, @oandrieu's suggestion ( |
Sorry, I'd put this on the proverbial backburner! Thanks @oandrieu - I didn't know about that switch and I've now changed my original use case in opam to use that instead of We should tidy up the |
Any news on this PR? If not we'll take it off the 4.06 milestone, as it is not particularly urgent. |
Taking this PR off the 4.06 milestone. |
No news for two years. C89 support looks less and less relevant. We should rather encourage the use of modern C standards. I'm taking the liberty to close this PR. |
The inline keyword is consequently no longer forced on MSVC builds.
This GCC flag encourages development of C files which will compile without error on older Microsoft C compilers.
The build failure in #9293 on msvc32 prompted me finally to finish this one off, because it would have prevented it. PR updated:
Combined, that means we:
I have not updated the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be nice if MSVC implemented the C99 standard... But I'm afraid we have to carry that cross.
This said, even for C compilers that implement C99, it is better to use static inline
instead of inline
, and the Caml_inline
macro encourages this good practice.
So, this PR is an improvement, and I'm in favor of merging. One suggested change below, but nothing essential.
otherlibs/systhreads/st_posix.h
Outdated
#else | ||
#define INLINE | ||
#define INLINE static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Caml_inline
is available on all platforms, I would simply replace INLINE
by Caml_inline
in this file and delete this #ifdef
nonsense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't totally sure about that, because inline
was only used for GCC, but I guess that could have been dropped when we introduced the C99 requirement. I pushed a commit tidying it up.
Isn't MSVC 2015 and higher versions implement C99? We (radare2) dropped
older MSVC compilers precisely because of this, and enforced C99 usage.
…On Thu, Feb 13, 2020, 02:12 Xavier Leroy ***@***.***> wrote:
***@***.**** approved this pull request.
Wouldn't it be nice if MSVC implemented the C99 standard... But I'm afraid
we have to carry that cross.
This said, even for C compilers that implement C99, it is better to use static
inline instead of inline, and the Caml_inline macro encourages this good
practice.
So, this PR is an improvement, and I'm in favor of merging. One suggested
change below, but nothing essential.
------------------------------
In otherlibs/systhreads/st_posix.h
<#1176 (comment)>:
> #else
-#define INLINE
+#define INLINE static
Since Caml_inline is available on all platforms, I would simply replace
INLINE by Caml_inline in this file and delete this #ifdef nonsense.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1176?email_source=notifications&email_token=AABRT7PJYF7CMCHVR5XSGR3RCQ3YZA5CNFSM4DL4NLT2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCVI2ENQ#pullrequestreview-357671478>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABRT7JABUEBOKLBDBAHV43RCQ3YZANCNFSM4DL4NLTQ>
.
|
Thanks, @xavierleroy - I'll merge once CI confirms the additional commit. @XVilka - IIUC, no version of MSVC is C99-compliant. When Microsoft rewrote their C runtime library in C++ to create the Universal CRT, the C99 support was vastly improved, and consequentially some C99 things were added to the compiler, but I think their stock answer has always been that it's a C++ compiler (and I believe the adherence to ISO C++ is at least less awful...) |
…caml#1176) This reverts commit 0f416573078fea425ed4bf22238232083b609f2e. Rectifying a mistake: this change shouldn't have been pushed without more discussion and a consensus. If we want to make this change, let's open an RFC first.
In other projects, it is useful to be able to tell GCC to run with
--std=c89
in order to write C code which is compatible with Microsoft's C compiler, but this disables theinline
keyword, as that's officially only part of C99.This GPR proposes altering the headers to use GCC's
__inline__
keyword, which is always available in GCC, and introduces a test in configure which adds a definition for__inline__
if the C compiler does not support it.I think that this "trick" using
--std=c89
to force compatibility with MSVC is a safe thing to do, but I'd very much appreciate input from someone who really gets the differences in semantics between -fgnu89-inline (which is also enabled by using--std=c89
) and C99 inline.