Skip to content

Dynamics

Jon Voigt Tøttrup edited this page Jun 16, 2018 · 2 revisions

The Dynamic struct is a wrapper type for all the basic C-types. The purpose of the Dynamic struct is to allow different data structures to work with data in a more abstract way. An added bonus is that storing a value as a reference is less cumbersome using Dynamics.

typedef struct _Dynamic
{
    DynType type;
    DynValue value;
} Dynamic;

Currently, the Dynamic struct consists of DynType and a DynValue value. The DynType contains the different basic C types.

typedef enum _DynType 
{
    BOOL,
    CHAR,
    STRING,
    INT,
    LONG,
    FLOAT,
    DOUBLE,
    REFERENCE
} DynType;

Note, that this includes the Reference type, which means that a primitive can contain a void pointer. This is useful for storing references to structs or unions.

Usage

The usage of the dynamic type is to implement type independent data structures (see "./src/stack/stack.h" for an implementation). When inputting actual data into a dynamic data structure, the Dynamic struct is used as a monad for containing the data. The data is stored by one of the aforementioned types. In order to use the struct easily, a series of functions have been implemented, two for each known and supported type; one for putting data into a dynamic struct and one for retrieving data. In order to promote usage, these functions have as short names as possible. See "/src/dynamic/dynamic.h" for the signatures of these.

Clone this wiki locally