From b432a527c4a38af45498691a44c5a88961b9c751 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 29 Jan 2018 13:42:36 -0500 Subject: [PATCH] c: remove __CHAR_UNSIGNED__ In C, `char`, `signed char`, and `unsigned char` are three separate, distinct types, so just because `char` happens to be signed does not mean it is interchangeable with `signed char`. --- CMakeLists.txt | 14 -------------- config.h.cmake.in | 5 ----- config.h.cmake.in.old-works | 5 ----- configure.ac | 1 - libsrc/posixio.c | 4 ---- libsrc/putget.m4 | 4 ---- nc_test/util.c | 4 ---- 7 files changed, 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c29e39b35b..342bee227a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1186,20 +1186,6 @@ MARK_AS_ADVANCED(ENABLE_SHARED_LIBRARY_VERSION) # Option checks ################################ -#### -# Check to see if char is signed or unsigned. -#### - -SET(SIGNED_TEST_SOURCE "\n - #include \n - int main(void) {\n - char error_if_char_is_signed[((char)-1) < 0 ? -1 : 1];\n - error_if_char_is_signed[0] = 0; - return -;\n -}\n") - -CHECK_C_SOURCE_COMPILES("${SIGNED_TEST_SOURCE}" __CHAR_UNSIGNED__) - # Library include checks CHECK_INCLUDE_FILE("math.h" HAVE_MATH_H) CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) diff --git a/config.h.cmake.in b/config.h.cmake.in index 4241017617..19e50ed6ba 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -553,11 +553,6 @@ are set when opening a binary file on Windows. */ /* Define for large files, on AIX-style hosts. */ #cmakedefine _LARGE_FILES ${_LARGE_FILES} -/* Define to 1 if type `char' is unsigned and you are not using gcc. */ -#ifndef __CHAR_UNSIGNED__ -#cmakedefine __CHAR_UNSIGNED__ -#endif - /* Define to `long int' if does not define. */ #cmakedefine off_t long int diff --git a/config.h.cmake.in.old-works b/config.h.cmake.in.old-works index fa63afa731..be1bbe2643 100644 --- a/config.h.cmake.in.old-works +++ b/config.h.cmake.in.old-works @@ -196,11 +196,6 @@ are set when opening a binary file on Windows. */ #cmakedefine SIZEOF_ULONGLONG @SIZEOF_ULONGLONG@ #cmakedefine SIZEOF_UNSIGNED_LONG_LONG @SIZEOF_UNSIGNED_LONG_LONG@ -/* Define whether char is signed by default. */ -#ifndef __CHAR_UNSIGNED__ -#cmakedefine __CHAR_UNSIGNED__ -#endif - /* The size of `void*` as computed by sizeof. */ #cmakedefine SIZEOF_VOIDSTAR @SIZEOF_VOIDSTAR@ /* The size of `char` as computed by sizeof. */ diff --git a/configure.ac b/configure.ac index 917b2fca52..0bddac3d8d 100644 --- a/configure.ac +++ b/configure.ac @@ -808,7 +808,6 @@ AC_STRUCT_ST_BLKSIZE UD_CHECK_IEEE AC_CHECK_TYPES([size_t, ssize_t, schar, uchar, longlong, ushort, uint, int64, uint64]) AC_TYPE_OFF_T -AC_C_CHAR_UNSIGNED AC_C_BIGENDIAN ### diff --git a/libsrc/posixio.c b/libsrc/posixio.c index 335d261caa..c6fa921dd2 100644 --- a/libsrc/posixio.c +++ b/libsrc/posixio.c @@ -740,11 +740,7 @@ px_get(ncio *const nciop, ncio_px *const pxp, pxp->bf_rflags |= rflags; pxp->bf_refcount++; -#ifndef __CHAR_UNSIGNED__ - *vpp = (void *)((char *)pxp->bf_base + diff); -#else *vpp = (void *)((signed char*)pxp->bf_base + diff); -#endif return NC_NOERR; } diff --git a/libsrc/putget.m4 b/libsrc/putget.m4 index 70987ba258..192aeb3b63 100644 --- a/libsrc/putget.m4 +++ b/libsrc/putget.m4 @@ -1198,11 +1198,7 @@ readNCv(const NC3_INFO* ncp, const NC_var* varp, const size_t* start, case CASE(NC_CHAR,NC_CHAR): case CASE(NC_CHAR,NC_UBYTE): -#ifndef __CHAR_UNSIGNED__ - return getNCvx_char_char(ncp,varp,start,nelems,(char*)value); -#else return getNCvx_schar_schar(ncp,varp,start,nelems,(signed char*)value); -#endif break; case CASE(NC_BYTE,NC_BYTE): return getNCvx_schar_schar(ncp,varp,start,nelems, (schar*)value); diff --git a/nc_test/util.c b/nc_test/util.c index d3cb4f0d86..811f7eacbc 100644 --- a/nc_test/util.c +++ b/nc_test/util.c @@ -342,11 +342,7 @@ int dbl2nc ( const double d, const nc_type xtype, void *p) * reporting it as a range error. */ if ( r < X_CHAR_MIN || r > X_CHAR_MAX ) return 2; -#if defined(__CHAR_UNSIGNED__) && __CHAR_UNSIGNED__ != 0 *((signed char*) p) = (signed char)r; -#else - *((char *) p) = (char)r; -#endif break; case NC_BYTE: r = floor(0.5+d);