Skip to content

Commit

Permalink
c: remove __CHAR_UNSIGNED__
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
mathstuf committed Feb 14, 2018
1 parent 7505bed commit b432a52
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 37 deletions.
14 changes: 0 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdlib.h>\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)
Expand Down
5 changes: 0 additions & 5 deletions config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sys/types.h> does not define. */
#cmakedefine off_t long int

Expand Down
5 changes: 0 additions & 5 deletions config.h.cmake.in.old-works
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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

###
Expand Down
4 changes: 0 additions & 4 deletions libsrc/posixio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 0 additions & 4 deletions libsrc/putget.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions nc_test/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b432a52

Please sign in to comment.