> > I'm hacking on the Autoconf scripts for the OCaml compiler [1]. I'm > > trying to make them more useful when compiling with the dreaded MSVC. > > Thanks for tackling this! Thanks for your reply and thorough comments. > (Can you check if there's maybe some way to make the UCRT declare > POSIX functions like open(), without a leading underscore, *even if* > __STDC__ is defined? Another macro that you define, maybe?) Indeed, there's one! I missed it. It's _CRT_DECLARE_NONSTDC_NAMES. The following program links without warnings with this invocation: cl -W4 -std:c11 -Zc:__STDC__ -D_CRT_DECLARE_NONSTDC_NAMES test.c #include <io.h> int open(const char *, int, ...); int main(void) {} > Because the C standard doesn't allow non-standard names in header > files, by default /std:c11 and /std:c17 don't expose the default > names for POSIX functions, types, and macros. If these names are > necessary, define _CRT_DECLARE_NONSTDC_NAMES to expose them. https://learn.microsoft.com/en-us/cpp/c-runtime-library/compatibility?view=msvc-170 The documentation is sometimes a bit confused between C, C++, names being exposed or not, or generating warnings, or the actual relations between all that. > > However the VLA test is included as-is in the C11 main program, but > > C11 made that feature optional. MSVC correctly defines the > > `__STDC_NO_VLA__` macro, but fails the Autoconf test. This is clearly > > an Autoconf bug, but the fix isn't clear. > > I think what we should do here is fold AC_C_VARARRAYS into AC_PROG_CC. > Take the test for VLAs completely out of _AC_C_C99_TEST_MAIN, but > unconditionally *run* a test for VLAs as part of AC_PROG_CC. If that > test fails, and __STDC_NO_VLA__ was not defined by the compiler, > then AC_DEFINE([__STDC_NO_VLA__], 1) and set a cache variable. > Mark AC_C_VARARRAYS as obsolete (i.e. AU_DEFUN it) and have it > just check the cache variable and AC_DEFINE(HAVE_C_VARARRAYS), > with post-autoupdate diagnostics telling the reader to replace > HAVE_C_VARARRAYS with !__STDC_NO_VLA__ and then remove the > compatibility code. Do you know how to do all of that? I can > do it (not for another couple of weeks) if it sounds too daunting, It does seem a bit daunting... I can try, you've well explained the path to follow. > but I will need you to test it for me as I don't have convenient > access to a compiler that doesn't support VLAs. GCC and clang have a -Wvla flag that warns if VLAs are encountered. Coupled with -Werror, you cannot miss one. -- Antonin