Standard-Types

Declares some printf/scanf format specifiers and type descriptions.  And adds standard definition for supporting unicode encoded wide characters.

Summary
Standard-TypesDeclares some printf/scanf format specifiers and type descriptions.
CopyrightThis program is free software.
Files
C-kern/api/context/stdtypes.hHeader file Standard-Types.
C-kern/konfig.hIncluded from header Konfiguration.
Macros
format
integer format specifiersAdapts printf/scanf format specifiers to 32/64 bit architectures.
PRIuSIZEprintf unsigned int format specifier ‘zu’ for type size_t.
PRIxFCTprintf hexadecimal format specifier for type uintptrf_t.
SCNuSIZEscanf unsigned int format specifier ‘zu’ for type size_t.
integer
ramsize_tRamsize could be bigger than size_t to match 32 bit machines with more than 4GTB of ram.
uintptrf_tAn integer type big enough to hold a pointer to a function.
limits
OFF_MAXDeclares the maximum value of type off_t.
unicode
char32_tDefines the unicode code point as »32 bit unsigned integer«.

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2013 Jörg Seebohn

Files

C-kern/api/context/stdtypes.h

Header file Standard-Types.

C-kern/konfig.h

Included from header Konfiguration.

Macros

Summary
format
integer format specifiersAdapts printf/scanf format specifiers to 32/64 bit architectures.
PRIuSIZEprintf unsigned int format specifier ‘zu’ for type size_t.
PRIxFCTprintf hexadecimal format specifier for type uintptrf_t.
SCNuSIZEscanf unsigned int format specifier ‘zu’ for type size_t.
integer
ramsize_tRamsize could be bigger than size_t to match 32 bit machines with more than 4GTB of ram.
uintptrf_tAn integer type big enough to hold a pointer to a function.
limits
OFF_MAXDeclares the maximum value of type off_t.
unicode
char32_tDefines the unicode code point as »32 bit unsigned integer«.

format

integer format specifiers

Adapts printf/scanf format specifiers to 32/64 bit architectures.  These specificiers are taken from the C99 std header file “inttypes.h”.

Rationale

int64_t i ; printf("i = %lld\n", i) ;

This code does only work on 32 bit architectures where long long int is of type 64 bit.  On 64 bit architectures using the LP64 data model int64_t is defined as long int.  Therefore the following macros exist to adapt integer type to different architecture data models.

Usage

Instead of non portable code:

int64_t i ; printf("i = %lld\n", i) ; scanf( "%lld", &i) ;

Use portable code:

int64_t i ; printf("i = %" PRId64 "\n", i) ; scanf( "%" SCNd64, &i) ;

printf specifiers

They are prefixed with the correct length modifier ( ‘l’, ‘ll’ )

PRId8used to print type int8_t
PRId16used to print type int16_t
PRId32used to print type int32_t
PRId64used to print type int64_t
PRIu8used to print type uint8_t
PRIu16used to print type uint16_t
PRIu32used to print type uint32_t
PRIu64used to print type uint64_t
PRIuPTRused to print type uintptr_t
PRIxFCTused to print type uintptrf_t
PRIuSIZEused to print type size_t

scanf specifiers

They are prefixed with the correct length modifier ( ‘hh’, ‘h’, ‘l’, ‘ll’ )

SCNd8used to scan type int8_t
SCNd16used to scan type int16_t
SCNd32used to scan type int32_t
SCNd64used to scan type int64_t
SCNu8used to scan type uint8_t
SCNu16used to scan type uint16_t
SCNu32used to scan type uint32_t
SCNu64used to scan type uint64_t
SCNuPTRused to scan type uintptr_t

PRIuSIZE

#define PRIuSIZE "zu"

printf unsigned int format specifier ‘zu’ for type size_t.

PRIxFCT

#define PRIxFCT PRIxPTR

printf hexadecimal format specifier for type uintptrf_t.

SCNuSIZE

#define SCNuSIZE "zu"

scanf unsigned int format specifier ‘zu’ for type size_t.

integer

ramsize_t

typedef uint64_t ramsize_t

Ramsize could be bigger than size_t to match 32 bit machines with more than 4GTB of ram.

uintptrf_t

typedef uintptr_t uintptrf_t

An integer type big enough to hold a pointer to a function.  Type uintptr_t and uintptrf_t could differ in size.  But in POSIX pointer to symbols (man dlsym) are considered to fit in type (void*) therefore in most environments sizeof(uintptrf_t) == sizeof(uintptr_t).

limits

OFF_MAX

#define OFF_MAX INT64_MAX

Declares the maximum value of type off_t.  The size of off_t is checked in file “C-kern/test/compiletime/stdtypes.h”

unicode

char32_t

typedef uint32_t char32_t

Defines the unicode code point as »32 bit unsigned integer«.  The unicode character set assigns to every contained abstract character an integer number - also named its code point.  The range for all available code points (“code space”) is [0 ...  10FFFF].

UTF-32

char32_t represents a single unicode character as a single integer value

  • same as UTF-32.

wchar_t

The wide character type wchar_t is either of type signed 32 bit or unsigned 16 bit.  Depending on the chosen platform.  So it is not portable.

(Will be removed if upcoming C11 is supported by compiler)

Declares some printf/scanf format specifiers and type descriptions.
Global generic configurations.
#define PRIuSIZE "zu"
printf unsigned int format specifier ‘zu’ for type size_t.
#define PRIxFCT PRIxPTR
printf hexadecimal format specifier for type uintptrf_t.
#define SCNuSIZE "zu"
scanf unsigned int format specifier ‘zu’ for type size_t.
typedef uint64_t ramsize_t
Ramsize could be bigger than size_t to match 32 bit machines with more than 4GTB of ram.
typedef uintptr_t uintptrf_t
An integer type big enough to hold a pointer to a function.
#define OFF_MAX INT64_MAX
Declares the maximum value of type off_t.
typedef uint32_t char32_t
Defines the unicode code point as »32 bit unsigned integer«.
Close