Variant datatype library for C
Posted
by Joey Adams
on Stack Overflow
See other posts from Stack Overflow
or by Joey Adams
Published on 2010-04-29T04:42:33Z
Indexed on
2010/04/29
4:47 UTC
Read the original article
Hit count: 450
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 http://stackoverflow.com/questions/649649/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.
© Stack Overflow or respective owner