Unix equivalent of a variant??

Lowell Gilbert freebsd-questions-local at be-well.ilk.org
Tue Feb 1 11:40:00 PST 2005


Charles Swiger <cswiger at mac.com> writes:

> On Feb 1, 2005, at 11:43 AM, Jonathon McKitrick wrote:
> > I need the equivalent of a variant, however.  A hold-everything
> > variable
> > that can be any type in C/C++.  Is there something already out there
> > I can
> > use or should I just roll my own?
> 
> Your question probably belongs on comp.lang.c, but the cannonical way
> of handling "data of any type" is a memory buffer and a (void *).
> Watch out for host data alignment restrictions.

Or depending on the intent, a union, which will get the compiler to
take care of alignment.

Generally, though, avoiding typechecking is a hack best avoided...


-- 
Lowell Gilbert, embedded/networking software engineer, Boston area
		http://be-well.ilk.org/~lowell/


More information about the freebsd-questions mailing list