This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: conversions between vectors

>>>>> "Joseph" == Joseph S Myers <> writes:

 > On 21 Dec 2001, Aldy Hernandez wrote:
 >> "vector signed int".  Also, assignments between "signed int" and
 >> "unsigned int" are allowed even in pedantic mode.  So, IMO the above

 > And this (implict signed/unsigned conversions) is a source of security
 > holes.

But it follows C semantics.  You are allowed to copy signed int to
unsigned int without any warnings of any kind.  You are allowed to
send signed int into a function that expects unsigned int: no
warnings.  This is C.  If we outlaw signed/unsigned compatability with
vectors, then we have a hole in our language logic-- the rest of C
won't care about signness, but vectors will ?!.

And it'll make it a real pain to have:

        void foo (vector int x, vector int y)

you'll need 2 versions (with __builtin_types_compatible_p), or you'll
have to explicitly cast, something foreign to C for sign issues (for
assignments not comparisons).

 >> And wrt casting, it makes syntatic sense to allow casts (as they do
 >> now), even if valarrays don't allow it, as long as the vector size is
 >> the same for both types.  I don't think we should enforce a pedantic
 >> 1:1 relationship wrt valarrays and vector types.

 > The correspondence with valarrays was to some extent because those are a 
 > well-developed set of semantics known to work.  Start by documenting in 
 > the manual the correspondence with valarrays and, for C programmers, what 
 > this means, and what parts of it are implemented.  Only then propose 
 > specific extensions, with precise documentation for what they mean and 
 > when they are allowed, and justification in each case.

The correspondence is minimal IMO.  Valarrays are vectors of any type
(including arrays and aggregate types).  Vectors are merely vectors of
the base types (char, int, short, float, double).  Valarrays allow
overloaded arithmetic between them.  Vectors do not.  Valarrays allow
vectors of vectors.  Vectors do not.  Valarrays do not allow casts
between vectors.  Vectors do.

Compatability with valarray is a nice thought, but I don't think it's
quite relevant.  In documenting valarrays and C-vectors, we'll find
more differences than similarities.

But I'm willing to be convinced otherwise, given sufficient proof.

And back to unsignedness, which is my original point.  Can someone
provide a compelling reason why not to allow implicit unsigned and
signed assigments-- in the spirit of the language?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]