"Sigbjorn Finne (Intl Vendor)" wrote:
> Sven Panne wrote:
> > What's wrong with using Green Card? Its %enum generates the desired
> > mappings automatically and consistently. AFAIK, this type safety is
> > something even IDL compilers don't do for you.
> 
> Use whatever works best for you, but I'm not sure I agree with this
> statement re: enums. Care to expand? :)

OK, my mail was a little bit terse, so I'll try again with a hopefully
self-explaining example. First in IDL:

-- Foo.idl ----------------------------------------------
module Foo {

const int EXIT_FAILURE = 1;
const int EXIT_SUCCESS = 0;
typedef int status_t;
void exit ([in]status_t status);

const int SEEK_SET = 0;
const int SEEK_CUR = 1;
const int SEEK_END = 2;
typedef int whence_t;

typedef unsigned long off_t;
typedef int fd_t;
off_t lseek([in]fd_t fd, [in]off_t offset, [in]whence_t whence);
}
---------------------------------------------------------

And here in Green Card:

-- Bar.gc -----------------------------------------------
module Bar where

import StdDIS
import Word

%enum Status Int [ EXIT_FAILURE, EXIT_SUCCESS ]
%fun exit :: Status -> IO ()

%enum Whence Int [ SEEK_SET, SEEK_CUR, SEEK_END ]

newtype Offset = Offset Word32;
%dis offset x = Offset (word32 x)

newtype Fd = Fd Int;
%dis fd x = Fd (int x)

%fun lseek :: Fd -> Offset -> Whence -> IO Offset
---------------------------------------------------------

With Foo, the following silly things are possible (i.e. pass the
compiler silently):

   import Foo
   main = do print (eXIT_SUCCESS ^ sEEK_END + 42)
             lseek sEEK_CUR 99 eXIT_FAILURE
             exit sEEK_SET

Some of the errors in this code snippet seem artificial, but to be
honest, who knows the exact arguments of lseek without peeking into
the man pages (or /usr/include/unistd.h :-)  ?

With the Green Card version of the interface these kind of mistakes
are impossible because they lead to compile time errors. An additional
bonus: If e.g. some day, in a sudden fit of craziness, the POSIX people
decide to change the value of SEEK_END to 0xAFFE, you have to change
Foo.idl, but not Bar.gc.

I'm not an IDL grand master, so my question to the H/Direct wizards:
Is there a *simple* way to get a similar thing using IDL without
writing the marshalling/unmarshalling stuff by hand?

Cheers,
   Sven

P.S.: The DIS's (or DISes? Hmm...) for the newtypes in Bar.gc could
easily generated by Green Card, giving even less chance to get things
wrong. But I think this is already on the ToDo list.
-- 
Sven Panne                                        Tel.: +49/89/2178-2235
LMU, Institut fuer Informatik                     FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen              Oettingenstr. 67
mailto:[EMAIL PROTECTED]            D-80538 Muenchen
http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne

Reply via email to