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.
#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
/* -------------------------------------------------------------------------- */
#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
+
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 */
#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 )
-
#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
#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
#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
#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
#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 ) )
--- /dev/null
+/* $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
+
#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 */
--- /dev/null
+/* _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
+
/* 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