www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Binary operation on typedefs

reply Zarathustra <adam.chrapkowski gmail.com> writes:
Do you think is it bug?

typedef uint A;
typedef A    B;

const A a1 = cast(A)0x01;
const A a2 = cast(A)0x02;

const B b1 = cast(B)0x04;
const B b2 = cast(B)0x04;

const A a3 = a1 | a2; // great it's ok (a1, a2, a3 same type)
const A a4 = b1; // great it's ok (b1 is delivered from A)
const A a5 = a1 | b1; // ERROR, but why?

In my opinion result of a1 and b1 shoud be A type not uint.
Dec 15 2009
next sibling parent div0 <div0 users.sourceforge.net> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Zarathustra wrote:
 Do you think is it bug?
 
 typedef uint A;
 typedef A    B;
 
 const A a1 = cast(A)0x01;
 const A a2 = cast(A)0x02;
 
 const B b1 = cast(B)0x04;
 const B b2 = cast(B)0x04;
 
 const A a3 = a1 | a2; // great it's ok (a1, a2, a3 same type)
 const A a4 = b1; // great it's ok (b1 is delivered from A)
 const A a5 = a1 | b1; // ERROR, but why?
 
 In my opinion result of a1 and b1 shoud be A type not uint.

typedef is broken and is going to be removed from D2. So don't use it in D1 either. - -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iD8DBQFLKCVOT9LetA9XoXwRAslPAKCQG+l4j9d2LocGiTfOoCZCJSLC+wCdEfOn N4TYq8PSsl+oxsQh9tGiFtc= =ykHJ -----END PGP SIGNATURE-----
Dec 15 2009
prev sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Wed, 16 Dec 2009 02:45:35 +0300, Zarathustra  
<adam.chrapkowski gmail.com> wrote:

 Do you think is it bug?

 typedef uint A;
 typedef A    B;

 const A a1 = cast(A)0x01;
 const A a2 = cast(A)0x02;

 const B b1 = cast(B)0x04;
 const B b2 = cast(B)0x04;

 const A a3 = a1 | a2; // great it's ok (a1, a2, a3 same type)
 const A a4 = b1; // great it's ok (b1 is delivered from A)
 const A a5 = a1 | b1; // ERROR, but why?

 In my opinion result of a1 and b1 shoud be A type not uint.

typedef defines a new type. Use "alias" instead.
Dec 16 2009