Skip to content

Added support for Visual Studio 2010's C89/C90 standard - #364

Open
BrentDaMage wants to merge 1 commit into
JuliaStrings:masterfrom
BrentDaMage:vs2010
Open

BrentDaMage wants to merge 1 commit into
JuliaStrings:masterfrom
BrentDaMage:vs2010

Conversation

@BrentDaMage

@BrentDaMage BrentDaMage commented Sep 25, 2026 •

Copy link
Copy Markdown

I've made the following changes in the pursuit to compile utf8proc in Visual Studio 2010.
Since VS2010 doesn't support C99, I had to move some variable declarations to the top of their scopes.
The project luckily required surprisingly few changes in order to get it building on 2010.

@stevengj

stevengj commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Thanks! I'm not sure how to test for this going forward?

To support this properly, we should ideally add a CI test that builds with make C99FLAG="-std=c90", maybe added as another "matrix" option to https://github.com/JuliaStrings/utf8proc/blob/master/.github/workflows/make.yml

However, getting it to fully support C90 is probably more trouble than it is worth:

cc  -O2 -fPIC -std=c90 -Wsign-conversion -Wall -Wextra -Wc++-compat -pedantic -DUTF8PROC_EXPORTS  -c -o utf8proc.o utf8proc.c
In file included from utf8proc.c:44:
./utf8proc.h:119:9: warning: '_Bool' is a C99 extension
      [-Wc99-extensions]
  119 | typedef bool utf8proc_bool;
      |         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/21/include/stdbool.h:24:14: note: 
      expanded from macro 'bool'
   24 | #define bool _Bool
      |              ^
utf8proc.c:139:3: warning: // comments are not allowed in
      this language [-Wcomment]
  139 |   // Must be between 0xc2 and 0xf4 inclusive to be valid
      |   ^
2 warnings generated.

I suppose we could #ifdef the utf8proc_bool definition and get rid of // comments, but unfortunately C90 doesn't have a straightforward analogue of stdint.h for fixed-width integer types, which would be painful. (utf8proc.h has a workaround for the missing stdint.h that is specific to older Windows compilers.)

@stevengj

stevengj commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

There are some other instances of mixed declarations and code in the tests:

test/normtest.c:30:18: warning: mixing declarations and
      code is a C99 extension [-Wdeclaration-after-statement]
   30 |           size_t len;

test/printproperty.c:19:36: warning: mixing declarations
      and code is a C99 extension [-Wdeclaration-after-statement]
   19 |         const utf8proc_property_t *p = utf8proc_get_property(c);

test/case.c:64:23: warning: mixing declarations and code is
      a C99 extension [-Wdeclaration-after-statement]
   64 |      utf8proc_uint8_t str_00df[] = {0xc3, 0x9f, 0x00};

test/maxdecomposition.c:12:10: warning: variable
      declaration in for loop is a C99-specific feature [-Wc99-extensions]
   12 |     for (utf8proc_int32_t c = 0; c <= 0x110000; ++c) {

test/iterate.c:25:14: warning: variable declaration in for
      loop is a C99-specific feature [-Wc99-extensions]
   25 |         for (utf8proc_ssize_t i = 0; i < len ; i++) {

(Are variable declarations in for loops allowed by VS2010?)

I guess that we can test for this specific problem by compiling with something like -Wdeclaration-after-statement -Werror for the gcc-based CI tests.

@BrentDaMage

BrentDaMage commented Sep 25, 2026 •

Copy link
Copy Markdown
Author

Are variable declarations in for loops allowed by VS2010?

Sorry, I just realized I never tried to build any of the tests in VS2010, I just built utf8proc.h and utf8proc.c.
I also forgot just how much of this is likely working due to VS2010's compiler extensions. So while the main files build on VS2010, they (as well as the rest of the project) are likely much further from full C89/90 compliance.

I think -Wdeclaration-after-statement would likely be good enough to retain general support for VS2010, since a lot of those other warnings are not issues due to VS2010's compiler extensions.

@BrentDaMage

Copy link
Copy Markdown
Author

In terms of compiling with VS2010 on our end, it was suggested that we could just build the library as C++ to obtain the necessary language features.

@stevengj

Copy link
Copy Markdown
Member

Building as C++ should also work.

This branch has not been deployed

No deployments
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.

2 participants