![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Kevin Wampler wrote:
> Upon actually reading the article,
> yeah, it's quite obvious that it's not real.
OK. You had me worried there for a minute. :-)
--
Darren New, San Diego CA, USA (PST)
Serving Suggestion:
"Don't serve this any more. It's awful."
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On 10/22/2010 12:16 PM, Warp wrote:
> Darren New<dne### [at] san rr com> wrote:
>> Warp wrote:
>>> 'union' in C is basically a construct which exists to save some bytes
>>> of memory in some rare circumstances.
>
>> I have also seen it used for typecasting, but nowadays I think casting the
>> address of the thing to the "wrong" pointer type and then indirecting it
>> gets used more. I.e.; { long x = ...; float f = *(float*)&x; }
>
> The most clever use of 'union' I have seen was like this:
>
> union Matrix4x4
> {
> double m[4][4];
> struct
> {
> double m11, m12, m13, m14,
> m21, m22, m23, m24,
> m31, m32, m33, m34,
> m41, m42, m43, m44;
> };
> };
>
> This means you can access the matrix like "transform.m[1][2] = 5;"
> or like "transform.m23 = 5;";
>
> Of course in this case this is just a trick to have two naming
> conventions to access the same data (rather than to save memory).
As they call it, Syntactic sugar.
I've seen unions as a means of assisting with reading binary file data,
but generally stored in a struct.
the Variant data type used by COM is a union. again, it has a field that
tells what the variant is, but it basically is there to allow data of
any type to be passed around. Not exactly type safe, but necessary for
programs written in VB that insist on not declaring any variable as a
particular type. Or for when you don't know what data type you will be
handing off (e.g. the clipboard)
--
~Mike
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On 26/10/2010 02:59 PM, Mike Raiford wrote:
> As they call it, Syntactic sugar.
Depends on your language.
In an object-oriented language, you generally don't need it, since
anything declared to be of class X can actually be of class X *or* any
subclass thereof.
In Haskell, "unions" are a fundamental part of the language. One of the
fundamental branching primitives is based on them. Nullable fields use
unions, lists are unions, trees are unions, just about everything ends
up being a union. [Insert witty Thatcher jokes here.]
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Invisible <voi### [at] dev null> wrote:
> In Haskell, "unions" are a fundamental part of the language. One of the
> fundamental branching primitives is based on them. Nullable fields use
> unions, lists are unions, trees are unions, just about everything ends
> up being a union. [Insert witty Thatcher jokes here.]
I'm not exactly sure if your concept of "union" is the same as C's
concept of "union". A union in C has a fixed size. It's not a dynamic
data container, like a list or a tree.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Warp wrote:
> It's not a dynamic data container, like a list or a tree.
Remember that in Haskell these are defined recursively. So a "tree" in this
case is union { struct { tree*left, tree*right }, struct { node data } }
A list is
union { struct {node data, list* next} , struct {node data} }
I.e., what he's calling "tree" would be "node of a tree" in C.
--
Darren New, San Diego CA, USA (PST)
Serving Suggestion:
"Don't serve this any more. It's awful."
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On 27/10/2010 07:27 PM, Darren New wrote:
> I.e., what he's calling "tree" would be "node of a tree" in C.
Yeah, I should have been clearer about that. A list *node* is a union. A
tree *node* is a union.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Orchid XP v8 <voi### [at] dev null> wrote:
> On 27/10/2010 07:27 PM, Darren New wrote:
> > I.e., what he's calling "tree" would be "node of a tree" in C.
> Yeah, I should have been clearer about that. A list *node* is a union. A
> tree *node* is a union.
What would the harm be if eg. list nodes were structs instead?
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
>>> I.e., what he's calling "tree" would be "node of a tree" in C.
>
>> Yeah, I should have been clearer about that. A list *node* is a union. A
>> tree *node* is a union.
>
> What would the harm be if eg. list nodes were structs instead?
Nothing. It's just that in Haskell, you can't implement it that way.
[Correction: You can't implement *finite* lists that way.] And, with
unions being a fundamental part of the language, you don't need to.
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Warp wrote:
> What would the harm be if eg. list nodes were structs instead?
Since "null" is a union in Haskell to (i.e., it either has data in it or it
has no data in it), this wouldn't really save you anything.
--
Darren New, San Diego CA, USA (PST)
Serving Suggestion:
"Don't serve this any more. It's awful."
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Darren New <dne### [at] san rr com> wrote:
> Warp wrote:
> > What would the harm be if eg. list nodes were structs instead?
> Since "null" is a union in Haskell to (i.e., it either has data in it or it
> has no data in it), this wouldn't really save you anything.
It saves checking the node type for each single operation you do to any
node in the list. It the node is a struct, its contents are fixed and thus
you don't have to check anything.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |