Re: Type safety, C++ and code generation



Maciej Sobczak wrote:

type ranged_type<int, 0, 250> Speed;
Speed s1, s2, s3; // with some values
s1 = s2 + s3; // OK
s1 = s2 * s3; // not OK

The addition is fine, but the multiplication should not be provided,
because speed multiplied by speed is not a speed. Can you extend your
class so that the compiler will refuse to compile the second operation
above?
(Ada, anyone? :) )

Just so it is visible:


procedure useop is

s1, s2, s3: SPEED; -- with some values

begin
s3 := s1 * s2;
end useop;

8. s3 := s1 * s2;
|
>>> cannot call abstract subprogram "*"

where

package Op is

type SPEED is range 0 .. 250;

function "*"(a, b: SPEED) return SPEED is abstract;

end Op;
.



Relevant Pages

  • Re: Type safety, C++ and code generation
    ... It uses the "negative logic" - in other words, specifies what is forbidden, not what is allowed - so it's more prone to errors than the "positive logic", where you specify what *is* supported instead. ... In the "positive logic" approach you can start with the default setting and the compiler will point you to each new operation usage in your code - then, you can either consciously extend the type definition to cover the new use case or reject it if it was a bug. ...
    (comp.lang.ada)
  • Re: Compiling with another compiler than gcc - OT reply
    ... Compiling with another compiler than gcc. ... For some reason it or the pre-processor like to sign extend ... Kermit - running about 40K compiled - and set the transmission ... Bill Vermillion - bv @ wjv. ...
    (freebsd-current)
  • Re: C# Error CS1034: compiler limit exceeded (2046 characters)
    ... The line length is by design, AFAIK, and no, you can't extend the length. ... "line" really means "statement" to the compiler. ... I generated the code using wsdl.exe and the SOAP ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Custom key words and statements in C#, possible?
    ... > possible to extend C# by creating custom made key words and statements? ... If you write your own compiler (or ... extend the Mono one, for example) you can make it do whatever you like. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Type safety, C++ and code generation
    ... Maciej Sobczak wrote: ... Above, R1 and R2 are equal to the compiler, but R3 is distinct from ... especially when you think in terms of different *domains*, no matter ... Ada programming at: http://ada.krischik.com ...
    (comp.lang.ada)