From: "Brian Budge" <brian.budge@gmail.com>
To: "Harri Järvi" <harri.jarvi@ajatus.org>
Cc: "Christian Schoenebeck" <cuse@users.sourceforge.net>,
gcc-help@gcc.gnu.org, "Andrew Haley" <aph@gcc.gnu.org>,
linuxsampler-devel@lists.sourceforge.net
Subject: Re: [Linuxsampler-devel] Re: GCC Vector Extensions
Date: Wed, 19 Apr 2006 15:14:00 -0000 [thread overview]
Message-ID: <5b7094580604190814j326ca898mba1a2eb4e0cb75e4@mail.gmail.com> (raw)
In-Reply-To: <20060419145843.GA13273@novelli>
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@ajatus.org> 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
>
prev parent reply other threads:[~2006-04-19 15:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-07 19:03 Christian Schoenebeck
2006-04-07 20:16 ` Greg Buchholz
2006-04-15 0:58 ` Christian Schoenebeck
2006-04-18 10:04 ` Andrew Haley
2006-04-18 23:38 ` Christian Schoenebeck
2006-04-19 8:30 ` Andrew Haley
2006-04-19 12:19 ` Christian Schoenebeck
2006-04-19 13:13 ` John Love-Jensen
2006-04-19 14:03 ` Andrew Haley
2006-04-19 15:20 ` Andrew Haley
2006-04-19 20:05 ` Christian Schoenebeck
2006-04-19 20:25 ` Andrew Haley
2006-04-19 14:58 ` [Linuxsampler-devel] " Harri Järvi
2006-04-19 15:14 ` Brian Budge [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5b7094580604190814j326ca898mba1a2eb4e0cb75e4@mail.gmail.com \
--to=brian.budge@gmail.com \
--cc=aph@gcc.gnu.org \
--cc=cuse@users.sourceforge.net \
--cc=gcc-help@gcc.gnu.org \
--cc=harri.jarvi@ajatus.org \
--cc=linuxsampler-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).