[M3devel] Shorthand type declarations?

Jay K jay.krell at cornell.edu
Wed Feb 3 12:55:22 CET 2010


  > so you can use a Cursor where a Window would be required etc

 

Win32 does opaque unique types something like:

 


#define DECLARE_HANDLE(foo) struct tag##foo; typedef struct tag##foo* foo;

 

 DECLARE_HANDLE(HWND)

 DECLARE_HANDLE(HCURSOR) 

 DECLARE_HANDLE(HRGN) 

 DECLARE_HANDLE(HPEN) 

 

Some of the objects are indeed "bases" of others, but that can't be

easily captured. It gets documented and you can cast.

 

And then opaque non-unique is also common:

typedef void* HANDLE;

That is used for files, events, mutexes, semaphores, processes, threads, etc.

And there is a lot of commonality.

They all work with CloseHandle, WaitForSingleObject, WaitForMultipleObjects,

DuplicateHandle, etc.

 

 - Jay

 
> Date: Wed, 3 Feb 2010 10:18:14 +0100
> From: wagner at elegosoft.com
> To: m3devel at elegosoft.com
> Subject: Re: [M3devel] Shorthand type declarations?
> 
> Quoting Chris <Highjinks at gmx.com>:
> 
> > On Tue, 02 Feb 2010 21:37:33 -0600
> > "Rodney M. Bates" <rodney_bates at lcwb.coop> wrote:
> >
> >> Unfortunately, this is the shortest you can get. I suppose the 
> >> language designers
> >> thought that, while a whole lot of variables with the same type 
> >> were a likely
> >> case:
> >>
> >> VAR x, y, z, u, v, w, h, i, j, h, ... : INTEGER; ,
> >>
> >> that more than just a few type names that are synonyms for the same 
> >> type would not be common.
> >>
> >> You may think me certifiably masochist, but I go the more 
> >> longhanded way and write:
> >>
> >> TYPE Window = unsigned_int;
> >> TYPE Pixmap = unsigned_int;
> >> TYPE Cursor = unsigned_int; ,
> >>
> >> sacrificing writeability in favor of readability. (Yes, I repeat 
> >> VAR and CONST too,
> >> almost every time.
> >
> > The reason I asked is because I'm doing the interface for 
> > /usr/include/xcb/xproto.h
> >
> > There are a lot of of typedefs in there that are defined as the same 
> > base type.
> >
> > I've shortened the Iterator types by using...
> >
> > TYPE T = UNTRACED ROOT OBJECT END;
> > TYPE XCB_Iterator = T OBJECT
> > Rem : INTEGER;
> > Index : INTEGER
> > END;
> >
> > TYPE XCBAtom = unsigned_int;
> > TYPE Atom_Iterator = XCB_Iterator OBJECT
> > Atom_Data : UNTRACED REF XCBAtom;
> > END;
> >
> > But even this is gonna kill me. Heh. xproto.h is a HUGE file.
> 
> What exactly is gained by defining all those aliases for unsigned_int?
> In M3 all the types are structurally equivalent, so you can use a Cursor
> where a Window would be required etc. It looks like a bit of facelifting
> to me.
> 
> And if it's only for readability and proper naming, all those should
> surely be named <x>Handle, shouldn't they?
> 
> The same level of abstraction could be achieved by defining just one
> XProtoHandle as unsigned_int, couldn't it?
> 
> I think I just have never understood the usefulness of interfaces
> too large to remember, but that may be a general problem with X...
> 
> Olaf
> -- 
> Olaf Wagner -- elego Software Solutions GmbH
> Gustav-Meyer-Allee 25 / Gebäude 12, 13355 Berlin, Germany
> phone: +49 30 23 45 86 96 mobile: +49 177 2345 869 fax: +49 30 23 45 86 95
> http://www.elegosoft.com | Geschäftsführer: Olaf Wagner | Sitz: Berlin
> Handelregister: Amtsgericht Charlottenburg HRB 77719 | USt-IdNr: DE163214194
> 
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100203/00a502d4/attachment-0002.html>


More information about the M3devel mailing list