Re: Type safety, C++ and code generation




<adaworks@xxxxxxxxxxxxx> wrote in message
news:o%35g.64094$_S7.49734@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

"Maciej Sobczak" <no.spam@xxxxxxxxxxx> wrote in message
news:e2qn8t$n13$1@xxxxxxxxxxxxxxxxxx

What about making different types really distinct?

typedef ranged_type<int, 0, 100> R1;
typedef ranged_type<int, 0, 100> R2;
typedef ranged_type<int, 0, 101> R3;


Above, R1 and R2 are *equal* to the compiler, but R3 is distinct from the
other two.
This example raises the issue of structural equivalence versus
name equivalence. In Ada R1 and R2 would not be
equivalent.

Ada is designed for name equivalence. Most other languages
are designed for structural equivalence. In this respect, Ada
continues to be just a wee bit more type safe than languages
designed for structural equivalence.

Richard Riehle

C++ does not use structural equivalence (nor does C). It too uses name
equivalence. The problem is that typedef does not introduce a new name, but
an alias. The only way to introduce a new name is via enum, struct, class,
or union. templates also introduce new names, but instantiation with the
same set of parameters are of the same name. structs defined with the exact
same fields but different names, are different.

REH


.



Relevant Pages

  • Re: Certified C compilers for safety-critical embedded systems
    ... Ada requires the function return type to match the array index type. ... This is invalid because the function beauty_index always returns ... For Ada this structural equivalence is meaningless. ...
    (comp.arch.embedded)
  • Re: Type safety, C++ and code generation
    ... This example raises the issue of structural equivalence versus ... Ada is designed for name equivalence. ... continues to be just a wee bit more type safe than languages ... Richard Riehle ...
    (comp.lang.ada)