Skip to content

Commit

Permalink
Update MSVC compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dr8co committed Apr 19, 2024
1 parent 1bd6dc6 commit 3097c3d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ project(LiteString
HOMEPAGE_URL "https://github.com/dr8co/LiteString"
LANGUAGES C CXX)

if (MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:clatest")
else ()
# C23 is not supported by MSVC, as of cl 19.37.32824
if (NOT MSVC)
set(CMAKE_C_STANDARD 23)
endif ()

Expand Down
2 changes: 1 addition & 1 deletion lite_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#endif

#define HAVE_STRNCASECMP 1
#if _MSC_VER || _WIN32 || _WIN64
#if _MSC_VER || _WIN32 || _WIN64 || WIN32
#define strncasecmp _strnicmp // Windows equivalent
#elif _GNU_SOURCE || _DEFAULT_SOURCE
// strncasecmp is available
Expand Down
16 changes: 13 additions & 3 deletions lite_string.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#ifndef LITE_STRING_NO_RESTRICT
#define LITE_STRING_NO_RESTRICT 0
#endif // LITE_STRING_NO_RESTRICT

#if LITE_STRING_NO_RESTRICT

// Ignore the warning for redefining the 'restrict' keyword
Expand All @@ -16,7 +20,7 @@
#endif // __clang__
#endif // LITE_STRING_NO_RESTRICT

#if __cplusplus
#if defined(__cplusplus) && __cplusplus
#if !LITE_STRING_NO_RESTRICT // The keyword has not been redefined
#if __GNUC__ || __clang__ || _MSC_VER // Support for '__restrict' in C++

Expand Down Expand Up @@ -89,7 +93,13 @@ extern "C" {
#endif // __has_c_attribute(gnu::nothrow)

#else // C23 is not supported
#ifndef __cplusplus
#if _MSC_VER
#include <stdbool.h>
#define nullptr ((void *) 0)
#endif
#endif


#if __has_c_attribute(__warn_unused_result__) // GNU 'warn_unused_result' attribute, pre-C23 syntax
#define LITE_ATTR_NODISCARD __attribute__((__warn_unused_result__))
Expand Down Expand Up @@ -128,7 +138,7 @@ extern "C" {

typedef struct lite_string lite_string; ///< The \p lite_string type.

LITE_ATTR_NODISCARD LITE_ATTR_HOT lite_string *string_new();
LITE_ATTR_NODISCARD LITE_ATTR_HOT lite_string *string_new(void);

LITE_ATTR_HOT void string_free(lite_string *restrict s);

Expand Down Expand Up @@ -304,6 +314,6 @@ LITE_ATTR_NODISCARD LITE_ATTR_UNSEQUENCED lite_string *string_from_float(float v

LITE_ATTR_NODISCARD LITE_ATTR_UNSEQUENCED lite_string *string_from_ldouble(long double value);

#if __cplusplus
#if defined(__cplusplus) && __cplusplus
}
#endif

0 comments on commit 3097c3d

Please sign in to comment.