comp.lang.ada
 help / color / mirror / Atom feed
* win32ada design question/problem
@ 1998-11-13  0:00 Mats Weber
  1998-11-13  0:00 ` Tom Moran
  1998-11-13  0:00 ` dennison
  0 siblings, 2 replies; 31+ messages in thread
From: Mats Weber @ 1998-11-13  0:00 UTC (permalink / raw)


I just had a look at the win32ada binding and found that I could not use
it as I would like. Lets take this function as an example:

>     function WriteFile(hFile                 : Win32.Winnt.HANDLE;
>                        lpBuffer              : Win32.LPCVOID;
>                        nNumberOfBytesToWrite : Win32.DWORD;
>                        lpNumberOfBytesWritten: Win32.LPDWORD;
>                        lpOverlapped          : Win32.Winbase.LPOVERLAPPED)
>                                                return Win32.BOOL;

>    type    DWORD      is access all ULONG; 

Now I want to call this from some procedure:

procedure P is

   bytes_Written : aliased ULONG;
   result        : Win32.bool;

begin
   result := WriteFile(..., 
                       lpNumberOfBytesWritten => bytes_Written'Access,
                       ...);
end P;

The problem is that this does not compile because of accessibility
checks (bytes_Written is less global than the access type).

Of course I can use 'Unchecked_Access to circumvent this, but then I
don't think that the binding is well designed if it requires
'Unchecked_Access all over the place in code that uses it.

The samples directory is full of examples that, in order to be able to
use'Access instead of 'Unchecked_Access, declare all parameters to Win32
as global variables, an approach that is totally incompatible with
multitasking programs.

Another problem is the use of the type

> type    PCCH       is access constant CHAR; 

to pass pointers to strings (it is used in e.g. gethostbyname). Now if I
want to use this, what should I do ? Pass an 'Unchecked_Access to the
first element of the string, and the function is going to read the whole
string ? I don't think this is very clean.

Example:

declare
   S : constant String := ...;
begin
   x := gethostbyname(s(s'first'unchecked_access));
end;

or is there a better way ?

Does the win32ada binding really have the above problems, or am I
missing something ?




^ permalink raw reply	[flat|nested] 31+ messages in thread
* Re: win32ada design question/problem
@ 1998-11-19  0:00 tmoran
  1998-11-19  0:00 ` dennison
  0 siblings, 1 reply; 31+ messages in thread
From: tmoran @ 1998-11-19  0:00 UTC (permalink / raw)


>   C_Function(S'Address);
>
>makes it clear that you are passing the whole of S.
> ....
>   C_Function(S(S'first)'Unchecked_Access);
>
>which does not make clear that S is passed as a whole.
   C_Function(Window_Name => S(S'first)'Unchecked_Access);
or
   C_Function(Control_Character => S(S'first)'Unchecked_Access);
Using a named parameter should make it clearer in either case.
A maintainer familiar with C would realize that all of S is
potentially accessible by S(S'first)'Unchecked_Access and would
have to look up C_Function to find out if it's acting on just
(S'first) or other parts of S.  Ditto S'Address.
(And of course S probably is intended to be an Interfaces.C.Char_Array,
not an Ada String.)

>- Try interfacing fcntl, setsockopt or some other weird functions using
>access types: these somtimes return, or take as a parameter, a pointer
>that points to a type that changes depending on the function you want to
>perform, which is determined by the value of another parameter. You can
>certainly do this with overloading, but I am not sure this buys much in
>a thin binding.
  This certainly happens, but relatively rarely.  I take it as yet
another argument against too-thin bindings.

>- It's the good old Ada 83 way that has worked for 15 years now, wo why
>change ?
  Actually, no. My first Ada 83 compiler used fat pointers for
unconstrained arrays and S'Address would not do what you expected in that
case - it was necessary to use S(S'first)'Address.
Tom Moran




^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~1998-11-27  0:00 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-13  0:00 win32ada design question/problem Mats Weber
1998-11-13  0:00 ` Tom Moran
1998-11-16  0:00   ` Mats Weber
1998-11-18  0:00     ` Tom Moran
1998-11-18  0:00       ` dennison
1998-11-19  0:00       ` Mats Weber
1998-11-19  0:00         ` dennison
1998-11-19  0:00           ` David Botton
1998-11-19  0:00         ` David Botton
1998-11-19  0:00           ` Mats Weber
1998-11-23  0:00             ` Marin David Condic
1998-11-19  0:00       ` Mats Weber
1998-11-27  0:00     ` Roga Danar
1998-11-13  0:00 ` dennison
1998-11-16  0:00   ` Stephen Leake
1998-11-16  0:00     ` Tucker Taft
1998-11-17  0:00     ` dennison
1998-11-17  0:00       ` Mats Weber
1998-11-17  0:00         ` dennison
1998-11-17  0:00           ` Mats Weber
1998-11-17  0:00           ` Tucker Taft
1998-11-18  0:00             ` Tom Moran
1998-11-18  0:00               ` dennison
  -- strict thread matches above, loose matches on Subject: below --
1998-11-19  0:00 tmoran
1998-11-19  0:00 ` dennison
1998-11-19  0:00   ` Tom Moran
1998-11-20  0:00     ` dennison
1998-11-20  0:00       ` Tom Moran
1998-11-23  0:00     ` Marin David Condic
1998-11-23  0:00       ` Mats Weber
1998-11-24  0:00         ` dennison

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox