Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variant datatype library for C

Is there a decent open-source C library for storing and manipulating
dynamically-typed variables (a.k.a. variants)? I'm primarily interested in atomic values (int8, int16, int32, uint, strings, blobs, etc.), while JSON-style arrays and objects as well as custom objects would also be nice. A major case where such a library would be useful is in working with SQL databases.

The most obvious feature of such a library would be a single type for all supported values, e.g.:

struct Variant {
    enum Type type;
    union {
        int8_t int8_;
        int16_t int16_;
        // ...
    };
};

Other features might include converting Variant objects to/from C structures (using a binding table), converting values to/from strings, and integration with an existing database library such as SQLite.

Note: I do not believe this is question is a duplicate of Any library for generic datatypes in C? , which refers to "queues, trees, maps, lists". What I'm talking about focuses more on making working with SQL databases roughly as smooth as working with them in interpreted languages.

like image 419
Joey Adams Avatar asked Apr 29 '10 04:04

Joey Adams


People also ask

What is variant data type in C?

Variant is a data type in certain programming languages, particularly Visual Basic, OCaml, Delphi and C++ when using the Component Object Model. It is an implementation of the eponymous concept in computer science.

What is a variant data type?

The Variant data type is the data type for all variables that are not explicitly declared as some other type (using statements such as Dim, Private, Public, or Static).

What is use of variant data type?

The variant data type can be used to define variables that contain any type of data. A tag is stored with the variant data to identify the type of data that it currently contains. You can examine the tag by using the VarType function.

What is variant data structure?

In computer science, a tagged union, also called a variant, variant record, choice type, discriminated union, disjoint union, sum type or coproduct, is a data structure used to hold a value that could take on several different, but fixed, types.


1 Answers

GLib has implementation of generic value types in form of GValue: http://library.gnome.org/devel/gobject/unstable/gobject-Generic-values.html

like image 160
el.pescado - нет войне Avatar answered Sep 22 '22 08:09

el.pescado - нет войне