gherkin: (C) Fix Windows related issues #193
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fix Windows related issues:
wchar_t
is 2 bytes in size.swprintf
In addition make the code conform to C90.
Details
When looking into #168, a set of problem were found and fixed.
wchar_t
is 2 bytes in size.Most Windows compilers use 2 bytes for wide characters (
wchar_t
), that mean the not all unicode code points can be represented by a wide character. To encode code points from the Supplementary Planes UTF-16 are used (using two wide characters for each code point). The decoding of UTF-8 (which is done directly in the code) need to use UTF-16 in the internal wide character representation when necessary.Windows generally does not use UTF-8, even when using unicode it is most likely UTF-16 and not UTF-8. Therefore it seems best to always do the UTF-8 encoding directly in the code, instead of relying on print functions form the complier libraries.
swprintf
Many (older) Windows compilers use a different signature for
swprintf
than the ISO standard (excluding the count argument in the signature), therefore it is better to avoid using it and instead calculate the string representation of the error location directly (which was the only use ofswprintf
).Another reason to avoid
swprintf
is that it did not exist in the ISO standard until C99.In addition make the code conform to C90.
After the use of
swprintf
was removed, only the use of//
for some commented out code was only thing that inhibit the compilation of the code with GCC (>v4.6) using-std=c90
(or-ansi
), so the use of//
was removed.Interestingly enough using -std=c90` with GCC (>v4.6) did not complain on repeated typedefs even though they are not allowed until C11. GCC (<v4.6) on the other hand does not allow them at all, so they are removed.
Motivation and Context
Fixes #168.
How Has This Been Tested?
On
OS name: "linux", version: "4.8.0-36-generic", arch: "amd64", family: "unix"
(ubuntu 16.04) using:gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
gcc (Alpine 6.2.1) 6.2.1 20160822
(docker)On
OS name: "linux", version: "4.4.0-72-generic", arch: "i386", family: "unix"
(ubuntu 16.04) using:gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
On
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
using:x86_64-w64-mingw32-gcc (GCC) 5.4.0
x86_64-pc-cygwin-gcc (GCC) 5.4.0
On
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"
using:i686-pc-mingw32-gcc (GCC) 4.5.2
i686-pc-cygwin-gcc (GCC) 4.7.3
Types of changes
Checklist: