comp.lang.ada
 help / color / mirror / Atom feed
From: "David Thompson" <david.thompson1@worldnet.att.net>
Subject: Re: Access to array slices?
Date: Mon, 27 Jan 2003 02:59:25 GMT
Date: 2003-01-27T02:59:25+00:00	[thread overview]
Message-ID: <hg1Z9.16060$zF6.1213296@bgtnsc04-news.ops.worldnet.att.net> (raw)
In-Reply-To: mailman.6.1042950604.265.comp.lang.ada@ada.eu.org

sk <sk@noname.com> wrote :
> tmoran@acm.org
>  > it will usually have "chars **buf" or "Handle *h" where ...
>
> A handy rule of thumb which I hope to remember (I think that
> "Handle *h" is largely a MS/Window thing isn't it ?).
>
MSWindows certainly uses handles extensively, but they
are far from the only people to do so.  MacOS did; I believe
X did; I've used lots of other libraries/packages which each
have their own (collection of) handle types.  It's a generic
and widely useful concept, or if you like pattern.

> david.thompson1@worldnet.att.net
>  > Allocation has nothing to do with it; a C routine cannot
>  > allocate unless it *returns* a pointer or receives a pointer
>  > *to* a pointer (or receives a pointer to or returns a struct
>  > *containing* a pointer, but that's much rarer).
>
> I seem to recall that some of the Window C routines allocated
> some of the data structures internally and passed a (or updated
> a passed in) pointer back to the caller ?
>
You can't "update a pointer passed in" in C; more generally,
no called routine can ever update a caller's actual argument,
only the value pointed to by a pointer argument and/or provide
a return value (which may be stored, or discarded, by the caller).

Another thing you can do (in general) is *not* give out actual
pointers; instead a called library maintains its own private
storage, possibly with dynamic/heap allocation and pointers
and possibly not, and gives out only numbers or other (private)
values that identify things within that private storage; these go
by a variety of names often including "number" or "index" or
"capability" e.g. a color index in a palette.  I don't know of
MSWindows using these but I haven't looked hard.  In C of
course this means e.g. return an int, or take a pointer to int.

--
- David.Thompson 1 now at worldnet.att.net






  reply	other threads:[~2003-01-27  2:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-15  1:17 Access to array slices? Wojtek Narczynski
2003-01-15  3:13 ` tmoran
2003-01-15 16:31   ` sk
2003-01-15 20:48     ` tmoran
2003-01-16  1:00       ` sk
2003-01-16  1:43         ` tmoran
2003-01-19  4:06     ` David Thompson
2003-01-15 14:44 ` Steve
2003-01-16  2:18   ` Wojtek Narczynski
2003-01-16  3:52     ` tmoran
2003-01-17 18:04     ` Warren W. Gay VE3WWG
2003-01-15 15:06 ` Stephen Leake
2003-01-16  2:02   ` Wojtek Narczynski
2003-01-16 16:18     ` Stephen Leake
2003-01-16 16:48 ` Victor Porton
2003-01-19  4:32 ` sk
2003-01-27  2:59   ` David Thompson [this message]
2003-01-24 19:02 ` Wojtek Narczynski
replies disabled

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