• Create Account

### #ActualServant of the Lord

Posted 28 December 2012 - 01:42 PM

Thanks SiCrane, I assumed there were prior proposals but didn't find them. I'll read over them.
Hm... Can I ask why this feature is vital? Conversion between
typedef unsigned int Centimeters;
typedef unsigned int Inches;
are legal as for me, as the real types are the same.

For incompatible types gcc (at least) drops an error: ...

For compatible types you won't get an error even without typedefs: ...

That's precisely the point. I don't want Centimeters and Inches to be convertible, except explicitly. Strong aliases should refuse to compile aliases made even from the same base type. You need a function to convert from Centimeters to Inches, because 1 Centimeter is not 1 Inch, and doing myCentimeters = myInches is easy to do and almost always a bug.

### #2Servant of the Lord

Posted 28 December 2012 - 01:41 PM

Thanks SiCrane, I assumed there were prior proposals but didn't find them. I'll read over them.
Hm... Can I ask why this feature is vital? Conversion between
typedef unsigned int Centimeters;
typedef unsigned int Inches;
are legal as for me, as the real types are the same.

For incompatible types gcc (at least) drops an error: ...

For compatible types you won't get an error even without typedefs: ...

That's precisely the point. I don't want Centimeters and Inches to be convertible, except explicitly. Strong aliases should refuse to compile aliases made even from the same base type. You need a function to convert from Centimeters to Inches, because 1 Centimeter is not 1 Inche, and doing myCentimeters = myInches is easy to do an almost always a bug.

### #1Servant of the Lord

Posted 28 December 2012 - 01:40 PM

Thanks SiCrane, I assumed there were prior proposals but didn't find them. I'll read over them.
Hm... Can I ask why this feature is vital? Conversion between
typedef unsigned int Centimeters;
typedef unsigned int Inches;
are legal as for me, as the real types are the same.

For incompatible types gcc (at least) drops an error:
[...code snip...]

For compatible types you won't get an error even without typedefs:
[...code snip...]

That's precisely the point. I don't want Centimeters and Inches to be convertible, except explicitly. Strong aliases should refuse to compile aliases made even from the same base type. You need a function to convert from Centimeters to Inches, because 1 Centimeter is not 1 Inche, and doing myCentimeters = myInches is easy to do an almost always a bug.

PARTNERS