Re: definition/explanation of an unboxed array in c is ...?
- From: "Malcolm McLean" <regniztar@xxxxxxxxxxxxxx>
- Date: Sun, 30 Sep 2007 19:46:08 +0100
"Eric Sosman" <esosman@xxxxxxxxxxxxxxxxxxxx> wrote in message
ben@xxxxxxxxxxxxxx wrote:Though the equivalent would be, for say a list of x, y, z co-ordinantesor 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.
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
.
- References:
- Prev by Date: Re: [OT]Translation for dummies [was Re: Set all bits to 1 in an array of raw bytes]
- Next by Date: Re: strange behavior with **double
- Previous by thread: Re: definition/explanation of an unboxed array in c is ...?
- Next by thread: Re: definition/explanation of an unboxed array in c is ...?
- Index(es):
Relevant Pages
|