Re: definition/explanation of an unboxed array in c is ...?



"Eric Sosman" <esosman@xxxxxxxxxxxxxxxxxxxx> wrote in message
ben@xxxxxxxxxxxxxx wrote:
or is "unboxed" and "unboxed arrays" not really applicable to c ?

"Unboxed" and "boxed" aren't C terms. In some object-
oriented languages, they refer (usually informally) to
simple primitive variables and to full-fledged objects,
respectively. In Java, for example, a `float' variable is
a primitive and a `Float' is an object with a `float' hidden
("boxed") inside it. (Why bother? Because an object is an
instance of a "class," and the class provides "methods" that
code can use without necessarily being fully aware of exactly
what kind of object is at hand. This is said to promote code
reuse; IMHO "promote" is some distance short of "guarantee.")

C has "objects," but not in the way O-O languages use the
term. C's objects are passive receptacles for values; an O-O
language would probably call them primitives or aggregates of
primitives. In other words, all C variables of all kinds are
"unboxed," and there is no way to "box" them.

Though the equivalent would be, for say a list of x, y, z co-ordinantes

float **coords;

as opposed to

float coords[100][3];

A more illuminating example might be a tree.

typedef struct node
{
struct node *left;
struct node *right;
double data;
}
is the obvious way to do it.

However

struct node
{
int right;
int left;
double data.
};

struct tree
{
struct node nodes[100]; /* left and right index into this array */
};

will tend to produce fewer pointer dereferences and execute faster.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

.



Relevant Pages