Skip to main content

IAR Embedded Workbench for RX 5.20

Added C functionality

In this section:

The DLIB runtime environment includes some added C functionality:

  • C bounds-checking interface

  • DLib_Threads.h

  • fenv.h

  • iar_dlmalloc.h

  • LowLevelIOInterface.h

  • stdio.h

  • stdlib.h

  • string.h

  • time.h (time32.h, time64.h)

C bounds-checking interface

The C library supports Annex K (Bounds-checking interfaces) of the C standard. It adds symbols, types, and functions in the header files errno.h, stddef.h, stdint.h, stdio.h, stdlib.h, string.h, time.h (time32.h, time64.h), and wchar.h.

To enable the interface, define the preprocessor extension __STDC_WANT_LIB_EXT1__ to 1 prior to including any system header file. See __STDC_WANT_LIB_EXT1__.

As an added benefit, the compiler will issue warning messages for the use of unsafe functions for which the interface has a safer version. For example, using strcpy instead of the safer strcpy_s will make the compiler issue a warning message.

DLib_Threads.h

The DLib_Threads.h header file contains support for locks and thread-local storage (TLS) variables. This is useful for implementing thread support. For more information, see the header file.

fenv.h

In fenv.h, trap handling support for floating-point numbers is defined with the functions fegettrapenable and fegettrapdisable.

iar_dlmalloc.h

The iar_dlmalloc.h header file contains support for the advanced (dlmalloc) heap handler. For more information, see Heap considerations.

LowLevelIOInterface.h

The header file LowLevelInterface.h contains declarations for the low-level I/O functions used by DLIB. See The DLIB low-level I/O interface.

stdio.h

These functions provide additional I/O functionality:

fdopen

Opens a file based on a low-level file descriptor.

fileno

Gets the low-level file descriptor from the file descriptor (FILE*).

__gets

Corresponds to fgets on stdin.

getw

Gets a wchar_t character from stdin.

putw

Puts a wchar_t character to stdout.

__ungetchar

Corresponds to ungetc on stdout.

__write_array

Corresponds to fwrite on stdout.

string.h

These are the additional functions defined in string.h:

strdup

Duplicates a string on the heap.

strcasecmp

Compares strings case-insensitive.

strncasecmp

Compares strings case-insensitive and bounded.

strnlen

Bounded string length.

time.h

There are two interfaces for using time_t and the associated functions time, ctime, difftime, gmtime, localtime, and mktime:

  • The 32-bit interface supports years from 1900 up to 2035 and uses a 32-bit integer for time_t. The type and function have names like __time32_t, __time32, etc. This variant is mainly available for backwards compatibility.

  • The 64-bit interface supports years from -9999 up to 9999 and uses a signed long long for time_t. The type and function have names like __time64_t, __time64, etc.

The interfaces are defined in three header files:

  • time32.h defines __time32_t, time_t, __time32, time, and associated functions.

  • time64.h defines __time64_t, time_t, __time64, time, and associated functions.

  • time.h includes time32.h or time64.h depending on the definition of _DLIB_TIME_USES_64.

    If _DLIB_TIME_USES_64 is:

    • defined to 1, it will include time64.h.

    • defined to 0, it will include time32.h.

    • undefined, it will include time32.h.

In both interfaces, time_t starts at the year 1970.

An application can use either interface, and even mix them by explicitly using the 32 or 64-bit variants.

See also __time32, __time64.

clock_t is 8 bytes if long is 8 bytes and 64-bit time.h is used, otherwise it is 4 bytes.

By default, the time library does not support the timezone and daylight saving time functionality. To enable that functionality, use the linker option ‑‑timezone_lib. See ‑‑timezone_lib.

There are two functions that can be used for loading or force-loading the timezone and daylight saving time information from __getzone:

  • int _ReloadDstRules (void)

  • int _ForceReloadDstRules (void)

Both these functions return 0 for DST rules found and -1 for DST rules not found.