Re: [Linuxsampler-devel] Re: GCC Vector Extensions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Seeing as how this is a gcc vector extension, why not add a special
casting mechanism?  The method described by Harri makes some sense,
because you could use static_cast to do an element by element cast and
reinterpret_cast to move between types via bitcopies.

Of course, since I believe this should be useful in C, templates are
not a viable method (and hence static_cast and reinterpret_cast) for
the C language.

A similar mechanism should be possible in C, although it may need to
end up being more verbose (ie. static_cast_v4sf_v4i(v4sf),
bit_cast_v4sf_v4i(v4sf) ).

  Brian

On 4/19/06, Harri Järvi <harri.jarvi@xxxxxxxxxx> wrote:
> On Wed, Apr 19, 2006 at 14:40:01 +0200, Christian Schoenebeck wrote:
> > int main() {
> >     const v4sf v = { 1.2f ,2.2f ,3.3f, 4.4f };
> >     printf("v4sf v = { %f, %f, %f, %f }\n", ((float*)&v)[0],((float*)&v)[1],((float*)&v)[2],((float*)&v)[3]);
> >     const v4i vRes = (v4i) v;
> >     printf("v4i vRes = { %d, %d, %d, %d }\n", ((int*)&vRes)[0],((int*)&vRes)[1],((int*)&vRes)[2],((int*)&vRes)[3]);
> > }
>
> Shouldn't one use c++-style casts instead. static_cast<type>() is the
> one I think would be the one to use here. C-style casts are ambigous and
> most of the time its difficult or impossible to know what they should
> do.
>
> This is the case because there is only one notation for all different
> type casts in C. In C++ you can use different type cast for different
> things.
>
> See http://www.cplusplus.com/doc/tutorial/typecasting.html
> for all 4 type casts in C++.
>
> -Harri
>


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux