diff options
| author | Tyge Løvset <[email protected]> | 2023-02-04 23:24:54 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-02-04 23:24:54 +0100 |
| commit | d2ff84c53aa9bd3857fdf22dcf7cd9398a4780be (patch) | |
| tree | 4923f88afb0d091d5d39ae03d65a4998a0517652 | |
| parent | 626b893b4d9e048c27571bfa28352914f2cd2bbc (diff) | |
| download | STC-modified-d2ff84c53aa9bd3857fdf22dcf7cd9398a4780be.tar.gz STC-modified-d2ff84c53aa9bd3857fdf22dcf7cd9398a4780be.zip | |
Fix in ccommon.h to make MSVC work again (without -std:c11) + small adjustments.
| -rw-r--r-- | docs/cspan_api.md | 4 | ||||
| -rw-r--r-- | include/stc/cbits.h | 4 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 2 | ||||
| -rwxr-xr-x | misc/examples/make.sh | 12 | ||||
| -rw-r--r-- | misc/tests/ctest.h | 12 |
5 files changed, 19 insertions, 15 deletions
diff --git a/docs/cspan_api.md b/docs/cspan_api.md index 650260a2..d0463b0a 100644 --- a/docs/cspan_api.md +++ b/docs/cspan_api.md @@ -18,8 +18,7 @@ using_cspan3(S, ValueType); // define span types S, S2, S3 with ran using_cspan4(S, ValueType); // define span types S, S2, S3, S4 with ranks 1, 2, 3, 4. ``` ## Methods -Note that `cspan_md()`, `cmake_from*()`, `cspan_atN()`, `and cspan_subspanN()` require a (safe) cast to its span-type -on assignment, but not on initialization of a span variable. All functions are type-safe, and arguments are side-effect safe, except for SpanType arg. which must not have side-effects. +All functions are type-safe, and index arguments are side-effect safe. ```c SpanTypeN cspan_md(ValueType* data, intptr_t xdim, ...); // create a multi-dimensional cspan SpanType cspan_make(T SpanType, {v1, v2, ...}); // make a 1d-dimensional cspan from values @@ -129,6 +128,7 @@ int main() { } ``` ## Example 2 +Slicing cspan without and with reducing the rank (like numpy array slicing): ```c #include <c11/fmt.h> #include <stc/cspan.h> diff --git a/include/stc/cbits.h b/include/stc/cbits.h index 9f0afc9c..577ecb13 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -60,10 +60,10 @@ int main() { #define _cbits_bytes(n) (_cbits_words(n) * c_sizeof(uint64_t)) #if defined(__GNUC__) || defined(__clang__) - STC_INLINE int cpopcount64(uint64_t x) {return (int)__builtin_popcountll(x);} + STC_INLINE int cpopcount64(uint64_t x) {return __builtin_popcountll(x);} #elif defined(_MSC_VER) && defined(_WIN64) #include <intrin.h> - STC_INLINE int cpopcount64(uint64_t x) {return __popcnt64(x);} + STC_INLINE int cpopcount64(uint64_t x) {return (int)__popcnt64(x);} #else STC_INLINE int cpopcount64(uint64_t x) { /* http://en.wikipedia.org/wiki/Hamming_weight */ x -= (x >> 1) & 0x5555555555555555; diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 30184407..b8ea6316 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -52,7 +52,7 @@ /* Macro overloading feature support based on: https://rextester.com/ONP80107 */ #define c_MACRO_OVERLOAD(name, ...) \ - c_PASTE(name##_, c_NUMARGS(__VA_ARGS__))(__VA_ARGS__) + c_PASTE(c_CONCAT(name,_), c_NUMARGS(__VA_ARGS__))(__VA_ARGS__) #define c_CONCAT(a, b) a ## b #define c_PASTE(a, b) c_CONCAT(a, b) #define c_EXPAND(...) __VA_ARGS__ diff --git a/misc/examples/make.sh b/misc/examples/make.sh index 0c4760a6..19a53880 100755 --- a/misc/examples/make.sh +++ b/misc/examples/make.sh @@ -6,14 +6,14 @@ if [ "$(uname)" = 'Linux' ]; then oflag='-o ' fi +cc=gcc; cflags="-s -O2 -std=c99 -Wconversion -Wpedantic -Wall -Wsign-compare -Wwrite-strings" #cc=gcc; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall $sanitize" -cc=gcc; cflags="-s -O2 -std=c99 -Wconversion -Wpedantic -Wall -Wsign-compare -Wwrite-strings" # -Wconversion #cc=tcc; cflags="-Wall -std=c99" #cc=clang; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall -Wsign-compare -Wwrite-strings" #cc=clang; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall -DSTC_CSTR_V1 -DSTC_CSMAP_V1" #cc=gcc; cflags="-x c++ -s -O2 -Wall -std=c++20" #cc=g++; cflags="-x c++ -s -O2 -Wall" -#cc=cl; cflags="-O2 -nologo -W2 -MD" +#cc=cl; cflags="-O2 -nologo -W3 -MD" #cc=cl; cflags="-nologo -TP" #cc=cl; cflags="-nologo -std:c11" @@ -40,13 +40,13 @@ fi if [ $run = 0 ] ; then for i in *.c ; do - echo $comp -I../include $i $clibs $oflag$(basename $i .c).exe - $comp -I../include $i $clibs $oflag$(basename $i .c).exe + echo $comp -I../../include $i $clibs $oflag$(basename $i .c).exe + $comp -I../../include $i $clibs $oflag$(basename $i .c).exe done else for i in *.c ; do - echo $comp -I../include $i $clibs - $comp -I../include $i $clibs + echo $comp -I../../include $i $clibs + $comp -I../../include $i $clibs if [ -f $(basename -s .c $i).exe ]; then ./$(basename -s .c $i).exe; fi if [ -f ./a.exe ]; then ./a.exe; fi if [ -f ./a.out ]; then ./a.out; fi diff --git a/misc/tests/ctest.h b/misc/tests/ctest.h index 4d42216c..373cda0e 100644 --- a/misc/tests/ctest.h +++ b/misc/tests/ctest.h @@ -93,8 +93,10 @@ struct ctest { #ifdef __APPLE__ #define CTEST_IMPL_SECTION __attribute__ ((used, section ("__DATA, .ctest"), aligned(1))) -#else +#elif !defined _MSC_VER #define CTEST_IMPL_SECTION __attribute__ ((used, section (".ctest"), aligned(1))) +#else +#define CTEST_IMPL_SECTION #endif #define CTEST_IMPL_STRUCT(sname, tname, tskip, tdata, tsetup, tteardown) \ @@ -445,7 +447,7 @@ static void sighandler(int signum) const char msg_nocolor[] = "[SIGSEGV: Segmentation fault]\n"; const char* msg = color_output ? msg_color : msg_nocolor; - intptr_t n = write(STDOUT_FILENO, msg, (unsigned int)strlen(msg)); + intptr_t n = write(1, msg, (unsigned int)strlen(msg)); (void)n; /* "Unregister" the signal handler and send the signal back to the process * so it can terminate as expected */ @@ -457,8 +459,10 @@ static void sighandler(int signum) #endif int ctest_main(int argc, const char *argv[]); - -__attribute__((no_sanitize_address)) int ctest_main(int argc, const char *argv[]) +#ifdef __GNUC__ +__attribute__((no_sanitize_address)) +#endif +int ctest_main(int argc, const char *argv[]) { static int total = 0; static int num_ok = 0; |
