]> pd.if.org Git - pdclib/commitdiff
Fixes to v0.1, added assert.h.
authorsolar <unknown>
Thu, 23 Dec 2004 09:26:39 +0000 (09:26 +0000)
committersolar <unknown>
Thu, 23 Dec 2004 09:26:39 +0000 (09:26 +0000)
Readme.txt
_PDCLIB_aux.h
_PDCLIB_config.h
_PDCLIB_int.h
assert.h [new file with mode: 0755]
float.h
functions/assert.c [new file with mode: 0644]
stdint.h

index 005a303e19c6a1ceb31b7250f6264be45381205e..c304046dc19d82acab31b427905ce74c37b6e6e5 100644 (file)
@@ -140,10 +140,10 @@ package, to leave <float.h> to the overlay, or devise some parameterized
 macro magic as for <limits.h> / <stdint.h>. Not thoroughly tested, but
 I had to make the 0.1 release sometime so why not now.
 
-Future releases:
-
-v0.2 - will (hopefully) add the INTN_C() / UINTN_C() macros, at least
-one overlay for GCC / x86, and implementations for <string.h> as well
-as parts of <stdlib.h>. I will also add a test driver to make at least
-some basic tests for syntax.
+v0.2 - unreleased
+Implements the INTN_C() / UINTN_C() macros, although I am not sure I got
+them right or missed something in how they are supposed to work.
 
+Should contain at least one overlay for GCC / x86, and implementations
+for <string.h> as well as parts of <stdlib.h>. I will also add a test
+driver to make at least some basic tests for syntax.
index 727f761bb2bf5d06d614dd357a4d0d31b58547b1..86712eefd4ef1550ce8958277aaa925836c242a1 100755 (executable)
 #endif
 
 #ifndef __STDC_VERSION__
-#define _PDCLIB_C_VERSION C90
+#define _PDCLIB_C_VERSION 90
 #elif __STDC_VERSION__ == 199409L
-#define _PDCLIB_C_VERSION C95
+#define _PDCLIB_C_VERSION 95
 #elif __STDC_VERSION__ == 199901L
-#define _PDCLIB_C_VERSION C99
+#define _PDCLIB_C_VERSION 99
 #else
 #error Unsupported _ _STDC_VERSION_ _ (__STDC_VERSION__) (supported: ISO/IEC 9899:1990, 9899/AMD1:1995, and 9899:1999).
 #endif
 #error Compiler does not define _ _STDC_HOSTED_ _ to 0 or 1 (not standard-compliant)!
 #endif
 
-#if _PDCLIB_C_VERSION != C99
-#error As of the current release, PDCLib only supports ISO/IEC 9899:1999 (C99).
+#if _PDCLIB_C_VERSION != 99
+#warning Up to and including v1.x, PDCLib is only aiming at ISO/IEC 9899:1999 (C99).
+#warning PDCLib might not be fully conforming to either C89 or C95 prior to v2.x.
 #endif
 
 #if _PDCLIB_HOSTED != 0
-#error As of the current release, PDCLib is not a conforming hosted implementation.
+#warning Up to the 1.x release, PDCLib is only complete as a freestanding environment.
+#warning PDCLib might not be fully conforming as a hosted environment.
 #endif
 
 /* -------------------------------------------------------------------------- */
@@ -55,3 +57,7 @@
 #define _PDCLIB_cc( x, y )     x ## y
 #define _PDCLIB_concat( x, y ) _PDCLIB_cc( x, y )
 
+#define _PDCLIB_symbol2value( x ) #x
+#define _PDCLIB_symbol2string( x ) _PDCLIB_symbol2value( x )
+#define _PDCLIB_symbol2identity( x ) x
+
index 7a749b4123a699aabe1f06268a297a356eb0decd..74eb290286d8178ca66e6cbb5b0db8fc1af7e286 100644 (file)
@@ -9,6 +9,13 @@
    Permission is granted to use, modify, and / or redistribute at will.
 */
 
+/* -------------------------------------------------------------------------- */
+/* Misc                                                                       */
+/* -------------------------------------------------------------------------- */
+
+/* The character (sequence) your platform uses as newline.                    */
+#define _PDCLIB_endl "\n"
+
 /* -------------------------------------------------------------------------- */
 /* Integers                                                                   */
 /* -------------------------------------------------------------------------- */
 
 #define _PDCLIB_intmax long long int
 #define _PDCLIB_INTMAX LLINT
+/* You are also required to state the literal suffix for the intmax type      */
+#define _PDCLIB_INTMAX_LITERAL ll
 
 /* -------------------------------------------------------------------------- */
 /* Floating Point                                                             */
@@ -153,4 +162,3 @@ typedef char * _PDCLIB_va_list;
 #define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 )
 #define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 )
 #define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 )
-
index 42b18957878058341c32bfb4e4c63e66e2db8d3b..bd0a47967453ba3eff13131b4c085e0f597738d4 100644 (file)
@@ -120,6 +120,8 @@ typedef unsigned char      _PDCLIB_uint8_t;
 #define _PDCLIB_INT8_MAX   _PDCLIB_CHAR_MAX
 #define _PDCLIB_INT8_MIN   _PDCLIB_CHAR_MIN
 #define _PDCLIB_UINT8_MAX  _PDCLIB_UCHAR_MAX
+#define _PDCLIB_INT8_LITERAL
+#define _PDCLIB_UINT8_LITERAL
 #else
 #error Unsupported width of char (not 8 bits).
 #endif
@@ -131,12 +133,16 @@ typedef unsigned int       _PDCLIB_uint16_t;
 #define _PDCLIB_INT16_MAX  _PDCLIB_INT_MAX
 #define _PDCLIB_INT16_MIN  _PDCLIB_INT_MIN
 #define _PDCLIB_UINT16_MAX _PDCLIB_UINT_MAX
+#define _PDCLIB_INT16_LITERAL
+#define _PDCLIB_UINT16_LITERAL
 #elif   _PDCLIB_SHRT_BYTES == 2
 typedef signed short       _PDCLIB_int16_t;
 typedef unsigned short     _PDCLIB_uint16_t;
 #define _PDCLIB_INT16_MAX  _PDCLIB_SHRT_MAX
 #define _PDCLIB_INT16_MIN  _PDCLIB_SHRT_MIN
 #define _PDCLIB_UINT16_MAX _PDCLIB_USHRT_MAX
+#define _PDCLIB_INT16_LITERAL  s
+#define _PDCLIB_UINT16_LITERAL us
 #else
 #error Neither 'short' nor 'int' are 16-bit.
 #endif
@@ -148,12 +154,16 @@ typedef unsigned int       _PDCLIB_uint32_t;
 #define _PDCLIB_INT32_MAX  _PDCLIB_INT_MAX
 #define _PDCLIB_INT32_MIN  _PDCLIB_INT_MIN
 #define _PDCLIB_UINT32_MAX _PDCLIB_UINT_MAX
+#define _PDCLIB_INT32_LITERAL
+#define _PDCLIB_UINT32_LITERAL
 #elif   _PDCLIB_LONG_BYTES == 4
 typedef signed long        _PDCLIB_int32_t;
 typedef unsigned long      _PDCLIB_uint32_t;
 #define _PDCLIB_INT32_MAX  _PDCLIB_LONG_MAX
 #define _PDCLIB_INT32_MIN  _PDCLIB_LONG_MIN
 #define _PDCLIB_UINT32_MAX _PDCLIB_LONG_MAX
+#define _PDCLIB_INT32_LITERAL  l
+#define _PDCLIB_UINT32_LITERAL ul
 #else
 #error Neither 'int' nor 'long' are 32-bit.
 #endif
@@ -164,12 +174,16 @@ typedef unsigned long      _PDCLIB_uint64_t;
 #define _PDCLIB_INT64_MAX  _PDCLIB_LONG_MAX
 #define _PDCLIB_INT64_MIN  _PDCLIB_LONG_MIN
 #define _PDCLIB_UINT64_MAX  _PDCLIB_ULONG_MAX
+#define _PDCLIB_INT64_LITERAL  l
+#define _PDCLIB_UINT64_LITERAL ul
 #elif _PDCLIB_LLONG_BYTES  == 8
 typedef signed long long   _PDCLIB_int64_t;
 typedef unsigned long long _PDCLIB_uint64_t;
 #define _PDCLIB_INT64_MAX  _PDCLIB_LLONG_MAX
 #define _PDCLIB_INT64_MIN  _PDCLIB_LLONG_MIN
 #define _PDCLIB_UINT64_MAX  _PDCLIB_ULLONG_MAX
+#define _PDCLIB_INT64_LITERAL  ll
+#define _PDCLIB_UINT64_LITERAL ull
 #else
 #error Neither 'long' nor 'long long' are 64-bit.
 #endif
@@ -235,6 +249,6 @@ typedef unsigned _PDCLIB_intmax _PDCLIB_uintmax_t;
 #define _PDCLIB_INTMAX_MIN  concat( concat( _PDCLIB_, _PDCLIB_INTMAX ), _MIN )
 #define _PDCLIB_INTMAX_MAX  concat( concat( _PDCLIB_, _PDCLIB_INTMAX ), _MAX )
 #define _PDCLIB_UINTMAX_MAX concat( concat( _PDCLIB_U, _PDCLIB_INTMAX ), _MAX )
-
-/* TODO: INTN_C / UINTN_C */
+#define _PDCLIB_INTMAX_C( value )  concat( value, _PDCLIB_INTMAX_LITERAL )
+#define _PDCLIB_UINTMAX_C( value ) concat( value, concat( u, _PDCLIB_INTMAX_LITERAL ) )
 
diff --git a/assert.h b/assert.h
new file mode 100755 (executable)
index 0000000..d5d61ec
--- /dev/null
+++ b/assert.h
@@ -0,0 +1,51 @@
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* 7.2 Diagnostics <assert.h>
+
+   This file is part of the Public Domain C Library (PDCLib).
+   Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#ifndef _PDCLIB_AUX_H
+#define _PDCLIB_AUX_H _PDCLIB_AUX_H
+#include <_PDCLIB_aux.h>
+#endif
+
+#ifndef _PDCLIB_CONFIG_H
+#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H
+#include <_PDCLIB_config.h>
+#endif
+
+#ifndef _PDCLIB_ASSERT_H
+#define _PDCLIB_ASSERT_H _PDCLIB_ASSERT_H
+#if _PDCLIB_C_VERSION == 99
+void _PDCLIB_assert( char const * const, char const * const, char const * const );
+#else
+void _PDCLIB_assert( char const * const );
+#endif
+#endif
+
+/* If NDEBUG is set, assert() is a null operation. */
+#undef assert
+
+#ifdef NDEBUG
+#define assert( ignore ) ( (void) 0 )
+#else
+#if _PDCLIB_C_VERSION == 99
+#define assert( expression ) ( ( expression ) ? (void) 0 \
+        : _PDCLIB_assert( "Assertion failed: " #expression \
+                          ", function ", __func__, \
+                         ", file " __FILE__ \
+                         ", line " _PDCLIB_symbol2string( __LINE__ ) \
+                         "." _PDCLIB_endl ) )
+#else
+#define assert( expression ) ( ( expression ) ? (void) 0 \
+       : _PDCLIB_assert( "Assertion failed: " #expression \
+                         ", file " __FILE__ \
+                         ", line " _PDCLIB_symbol2string( __LINE__ ) \
+                         "." _PDCLIB_endl ) )
+#endif
+#endif
+
diff --git a/float.h b/float.h
index 5b878fb0d5f3034167b57273fb6b80c2492b90f9..7c0136afff081053f6900068afddf033a07c80e0 100644 (file)
--- a/float.h
+++ b/float.h
@@ -29,8 +29,6 @@
 #define FLT_MANT_DIG 24
    /* Number of decimal digits of precision in a float */
 #define FLT_DIG 6
-   /* Addition rounds to 0: zero, 1: nearest, 2: +inf, 3: -inf, -1: unknown */
-#define FLT_ROUNDS 1
    /* Difference between 1.0 and the minimum float greater than 1.0 */
 #define FLT_EPSILON 1.19209290e-07F
    /* Minimum int x such that FLT_RADIX**(x-1) is a normalised float */
diff --git a/functions/assert.c b/functions/assert.c
new file mode 100644 (file)
index 0000000..31c4386
--- /dev/null
@@ -0,0 +1,27 @@
+/* _PDCLIB_assert( char * )
+
+   This file is part of the Public Domain C Library (PDCLib).
+   Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <_PDCLIB_aux.h>
+
+#if _PDCLIB_C_VERSION == 99
+void _PDCLIB_assert( char const * const message1, char const * const function, char const * const message2 )
+{
+    fputs( message1, stderr );
+    fputs( function, stderr );
+    fputs( message2, stderr );
+    abort();
+}
+#else
+void _PDCLIB_assert( char const * const message )
+{
+    fputs( message, stderr );
+    abort();
+}
+#endif
+
index 544edc8cdd639016245c722eec1e1ed4dde758a6..50d3a6e30cc299072009779761ee5f86346cf69d 100644 (file)
--- a/stdint.h
+++ b/stdint.h
@@ -179,35 +179,35 @@ typedef _PDCLIB_uintmax_t uintmax_t;
 
 /* 7.18.4.1 Macros for minimum-width integer constants */
 
+/* As the minimum-width types - for the required widths of 8, 16, 32, and 64
+   bits - are expressed in terms of the exact-width types, the mechanism for
+   these macros is to append the literal of that exact-width type to the macro
+   parameter.
+   This is considered a hack, as the author is not sure his understanding of
+   the requirements of this macro is correct. Any input appreciated.
+*/
+
 /* Expand to an integer constant of specified value and type int_leastN_t */
 
-/* NOT YET IMPLEMENTED
-#define INT8_C( value )
-#define INT16_C( value )
-#define INT32_C( value )
-#define INT64_C( value )
-*/
+#define INT8_C( value )  concat( value, _PDCLIB_INT8_LITERAL )
+#define INT16_C( value ) concat( value, _PDCLIB_INT16_LITERAL )
+#define INT32_C( value ) concat( value, _PDCLIB_INT32_LITERAL )
+#define INT64_C( value ) concat( value, _PDCLIB_INT64_LITERAL )
 
 /* Expand to an integer constant of specified value and type uint_leastN_t */
 
-/* NOT YET IMPLEMENTED
-#define UINT8_C( value )
-#define UINT16_C( value )
-#define UINT32_C( value )
-#define UINT64_C( value )
-*/
+#define UINT8_C( value )  concat( value, _PDCLIB_UINT8_LITERAL )
+#define UINT16_C( value ) concat( value, _PDCLIB_UINT16_LITERAL )
+#define UINT32_C( value ) concat( value, _PDCLIB_UINT32_LITERAL )
+#define UINT64_C( value ) concat( value, _PDCLIB_UINT64_LITERAL )
 
 /* 7.18.4.2 Macros for greatest-width integer constants */
 
 /* Expand to an integer constant of specified value and type intmax_t */
-/* NOT YET IMPLEMENTED
-#define INTMAX_C( value )
-*/
+#define INTMAX_C( value ) _PDCLIB_INTMAX_C( value )
 
 /* Expand to an integer constant of specified value and type uintmax_t */
-/* NOT YET IMPLEMENTED
-#define UINTMAX_C( value )
-*/
+#define UINTMAX_C( value ) _PDCLIB_UINTMAX_C( value )
 
 #endif