The long stor is, I am make a matrix class with SIMD enabled.
Some specific funtion I needed to use Intel SSE intrinsic function like
_mm_add_ps.
Therefore I want to keep the intrinsic type and a C-array in a union
something like
union {
__m128;
float[4];
};
But problem comes out when I use reference (because of some reason, I have
to use reference).
Since the cost of one reference is 4 bytes, by using union of reference, the
size of my object (reference to vector of 4 flaot) will be just 4 bytes
insteal of 8 bytes. That the reason I use union of reference
--
exmat - C++ matrix library
http://exmat.sourceforge.net
"Richard Herring" <junk@[127.0.0.1]> wrote in message
news:E9k5DhfqZ1IBFwMY@baesystems.com...[color=blue]
> In message <41241ac4@usenet.hk>, Ricky Lung <ricky@y-trace.com> writes[color=green]
> >struct Foo {
> > union {
> > int& i;
> > float& j;
> > };
> > Foo(int& val) :
> > i((int&)val), j((float&)val)[/color]
>
> All other considerations aside, how could you initialise a reference to
> float using an int? What would you expect to happen?
>[color=green]
> > {}
> >};
> >
> >GCC will fail to compile the above code because multiple union member is
> >being initialized.
> >But if I modify the code to just only init the reference i:
> >Foo(int& val) :
> > i((int&)val), j((float&)val)
> > {}
> >it also pop out error because reference j is not been initialized.
> >
> >What's the solution to the above problem? How the C++ standard say about
> >using reference in union?
> >[/color]
>
> What's the problem you're trying to solve by using a union?
>
> --
> Richard Herring[/color]
~ Samba, more than a low cost File and Printer server ~
-- Let us OpenSource --
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----