Writing Bug-Free C/D Code

Derek Parnell derek at nomail.afraid.org
Mon Mar 19 23:07:22 PDT 2007


On Mon, 19 Mar 2007 14:20:31 +0000 (UTC), Knud Soerensen wrote:

> Using a type system we can take the idea a step further.
> 
> typedef int ROWPOS;
> typedef int COLPOS;
> 
> foo 
> {
>   ROWPOS rowPos;
>   COLPOS colPos;
>  
>   rowPos = colPos; // error at compiler time.
> }
> 

Currently D doesn't seem to support typedefs (user defined types) as
cleanly as I'd hope it would.

------------
 import std.stdio;
 typedef float age;
 typedef float len;

 void main()
 {
   age x;
   len y;
   float z = 4.321;

   x = 10;
   y = 5;
   //y = z; // fails but probably shouldn't
   //y = x; // correctly fails.
   y += x;  // incorrectly works.

   writefln("x=%s y=%s", x, y);
 }

------------

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
20/03/2007 5:05:40 PM



More information about the Digitalmars-d mailing list