Extensions to the C standard library - DavidPH/GDCC GitHub Wiki

stdio.h extensions

Print format specifiers

GDCC supports the Embedded C conversion specifiers, r/R (for signed/unsigned _Fract) and k/K (for signed/unsigned _Accum/__fixed). They can use the standard length modifier l for long fixed point arguments.

GDCC only adds one conversion specifier of it's own, S, and implements all other needed features as length modifiers, to avoid using up more conversion specifiers.

  • When no length modifier is present (%S), the expected argument is of type __str/__str_ent * and is an ACS string to be printed. Corresponds to the s cast type in ACS.

  • If an L length modifier is present (%LS), the expected argument is of type __str/__str_ent * and is an ACS string, containing a localized string from LANGUAGE to be printed. Corresponds to the l cast type in ACS.

  • If a j length modifier is present (%jS), the expected argument is of type __str/__str_ent * and is an ACS string, containing the name of a keybind to print. Corresponds to the k cast type in ACS.

  • If a t length modifier is present (%tS), the expected argument is of type int and is an index for a name to be printed. Corresponds to the n cast type in ACS.

__*_str variants

Identical in functionality and return value to their non-_str variants, but the format string is replaced with an ACS string (__str/__str_ent *).

  • __fprintf_str
  • __printf_str
  • __snprintf_str
  • __sprintf_str
  • __vfprintf_str
  • __vprintf_str
  • __vsnprintf_str
  • __vsprintf_str

__nprintf

Identical to printf, except the output is written to the native print buffer (which in Hexen ACS and ZDACS is initialized with BeginPrint and flushed with EndPrint) rather than a stream.

  • int __nprintf(char __str_ars const *restrict format, ...)
  • int __nprintf_str(char __str_ars const *restrict format, ...) - ACS string variant.
  • int __vnprintf(char __str_ars const *restrict format, va_list arg) - like vprintf, but writes to the native print buffer.
  • int __vnprintf_str(char __str_ars const *restrict format, va_list arg) - ACS string variant.

stdlib.h extensions

String conversion functions

GDCC provides two more string conversion functions, strtoi and strtoui. They're identical to strtol and strtoul, but the intial portion of the string is converted to int and unsigned int, respectively.

  • int strtoi(char const *restrict nptr, char **restrict endptr, int base);
  • unsigned int strtoui(char const *restrict nptr, char **restrict endptr, int base);

If no conversion could be performed, 0 is returned. If the correct value is outside the range of representable values, INT_MAX, INT_MIN, or UINT_MAX is returned (according to the return type and sign of the value, if any), and the value of the macro ERANGE is stored in errno.

The primary reason for strtoi and strtoui is that they're faster than the equivalent standard long functions. Since the ACS VM doesn't support any types larger than 32-bits, GDCC needs to emulate the appropriate operations on them.