1.10.2 Basic Datatypes and Macros

A basic notion used in QSMM is signal. Signals are parts of an argument of a probabilistic mapping. A result of a probabilistic mapping is also a signal. Signals are carriers of actions. In QSMM, non-negative integer numbers identify signals. The header file sig.h included in qsmm.h and err.h defines datatypes for signal identifiers.

Data type: qsmm_sig_t

This is an unsigned integer datatype for storing signal identifiers and numbers of signals. The set of allowed values for the datatype is the range 0 to QSMM_SIG_MAX+1 and the special value QSMM_SIG_INVALID. The current implementation defines the datatype as unsigned int.

In principle, a developer can define the datatype as a different unsigned integer type. Corresponding modification of definitions of qsmm_ssig_t datatype and QSMM_SIG_MAX, QSMM_SIG_INVALID, QSMM_FMT_PRI_SIG, QSMM_FMT_PRI_SSIG, and QSMM_FMT_SCN_SIG macros (see below) may be necessary. The values QSMM_SIG_MAX+1 and QSMM_SIG_INVALID must lie in the range of allowed values of size_t type. This restriction means that the condition “sizeof(qsmm_sig_t)<=sizeof(size_t)” holds true.

Data type: qsmm_ssig_t

[New in QSMM 1.17] This is a signed integer datatype for storing signal identifiers and numbers of signals. The set of allowed values for the datatype is the range -(qsmm_ssig_t) QSMM_SIG_MAX-1 to QSMM_SIG_MAX+1 and the special value QSMM_SIG_INVALID. The current implementation defines the datatype as int. Specifics of defining the datatype as a different signed integer type are the same as for the datatype qsmm_sig_t. The condition “sizeof(qsmm_ssig_t)==sizeof(qsmm_sig_t)” must hold true.

Signal identifiers specify not only signals themselves but also other entities internally represented by signals. For example, identifiers of nodes of a multinode model and identifiers of their states are signal identifiers.

The following macros can be helpful when working with signal identifiers.

Macro: QSMM_SIG_INVALID

Represents an invalid signal identifier. Use it as a substitute for the NULL signal identifier value because identifier 0 is valid one. The macro expands to an unsigned integer value. In QSMM version 1.19.1, the macro expands to ((1 << (sizeof(qsmm_sig_t)*8-1))-0U).

Macro: QSMM_SIG_MAX

This is an unsigned integer value equal to the maximum allowed value of a signal identifier.

Consider two statements:

  1. When an array contains information on signals with identifiers in the range 0 to QSMM_SIG_MAX, the number of elements in the array is equal to QSMM_SIG_MAX+1.
  2. When the upper bound of a range of signal identifiers is not inclusive, the range x to QSMM_SIG_MAX has upper bound QSMM_SIG_MAX+1.

To make it possible to use the datatypes qsmm_sig_t and qsmm_ssig_t for specifying numbers of signals in the first case and signal ranges with not inclusive upper bounds in the second case, the mentioned datatypes additionally support storing value QSMM_SIG_MAX+1. The datatype qsmm_ssig_t additionally supports storing value -(qsmm_ssig_t) QSMM_SIG_MAX-1. In QSMM version 1.19.1, the macro expands to ((1 << (sizeof(qsmm_sig_t)*8-1))-2U).

Macro: QSMM_FMT_PRI_SIG

[New in QSMM 1.17] An optional length modifier and a conversion specifier in format strings for functions similar to printf for printing values of qsmm_sig_t type. The macro expands to ‘u’.

Macro: QSMM_FMT_PRI_SSIG

[New in QSMM 1.17] An optional length modifier and a conversion specifier in format strings for functions similar to printf for printing values of qsmm_ssig_t type. The macro expands to ‘d’.

Macro: QSMM_FMT_SCN_SIG

[New in QSMM 1.17] An optional length modifier and a conversion specifier in format strings for functions similar to scanf for parsing values of qsmm_sig_t type. The macro expands to ‘u’.

Below there is an example of using the datatype qsmm_sig_t and the macro QSMM_FMT_PRI_SIG. The function print_sig_array prints an array of signal identifiers specified by a pointer to the array and the number of its elements.

#include <stdio.h>
#include <qsmm/qsmm.h>

void
print_sig_array(
    const qsmm_sig_t *sigp,
    qsmm_sig_t nsig
) {
    putchar('[');
    for (qsmm_sig_t idx=0; idx<nsig; idx++) {
        if (idx) fputs(", ",stdout);
        printf("%" QSMM_FMT_PRI_SIG,sigp[idx]);
    }
    puts("]");
}