From 3220f577b186e04180acd7554a785c60dfb7ebb2 Mon Sep 17 00:00:00 2001 From: solar Date: Thu, 23 Dec 2004 09:26:39 +0000 Subject: [PATCH] Fixes to v0.1, added assert.h. --- Readme.txt | 12 +++++------ _PDCLIB_aux.h | 18 ++++++++++------ _PDCLIB_config.h | 10 ++++++++- _PDCLIB_int.h | 18 ++++++++++++++-- assert.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++ float.h | 2 -- functions/assert.c | 27 ++++++++++++++++++++++++ stdint.h | 36 ++++++++++++++++---------------- 8 files changed, 139 insertions(+), 35 deletions(-) create mode 100755 assert.h create mode 100644 functions/assert.c diff --git a/Readme.txt b/Readme.txt index 005a303..c304046 100644 --- a/Readme.txt +++ b/Readme.txt @@ -140,10 +140,10 @@ package, to leave to the overlay, or devise some parameterized macro magic as for / . 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 as well -as parts of . 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 as well as parts of . I will also add a test +driver to make at least some basic tests for syntax. diff --git a/_PDCLIB_aux.h b/_PDCLIB_aux.h index 727f761..86712ee 100755 --- a/_PDCLIB_aux.h +++ b/_PDCLIB_aux.h @@ -19,11 +19,11 @@ #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 @@ -38,12 +38,14 @@ #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 + diff --git a/_PDCLIB_config.h b/_PDCLIB_config.h index 7a749b4..74eb290 100644 --- a/_PDCLIB_config.h +++ b/_PDCLIB_config.h @@ -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 */ /* -------------------------------------------------------------------------- */ @@ -93,6 +100,8 @@ #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 ) - diff --git a/_PDCLIB_int.h b/_PDCLIB_int.h index 42b1895..bd0a479 100644 --- a/_PDCLIB_int.h +++ b/_PDCLIB_int.h @@ -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 index 0000000..d5d61ec --- /dev/null +++ b/assert.h @@ -0,0 +1,51 @@ +/* $Id$ */ + +/* Release $Name$ */ + +/* 7.2 Diagnostics + + 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 5b878fb..7c0136a 100644 --- 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 index 0000000..31c4386 --- /dev/null +++ b/functions/assert.c @@ -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 +#include + +#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 + diff --git a/stdint.h b/stdint.h index 544edc8..50d3a6e 100644 --- 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 -- 2.40.0