comp.lang.ada
 help / color / mirror / Atom feed
From: Dave Thompson <david.thompson1@worldnet.att.net>
Subject: Re: pointer questions
Date: Mon, 07 Nov 2005 04:21:10 GMT
Date: 2005-11-07T04:21:10+00:00	[thread overview]
Message-ID: <a5ltm1pmpcdft68v0fmqf7r32l2i2s8n1i@4ax.com> (raw)
In-Reply-To: op.szbefdq9z25lew@super

On Thu, 27 Oct 2005 20:19:51 +0300, "Martin Krischik"
<krischik@users.sourceforge.net> wrote:

> Am 27.10.2005, 02:01 Uhr, schrieb Szymon Guz <alpha@skynet.org.pl_WITHOUT>:
<snip>
> > 2. Is there a universal (like above) pointer for procedure|function that  
> >   can point to any kind of procedure|funcion ?
> 
> How is that supposed to work? Any function - how then are you going to  
> pass any parameters? You don't even have that in C.
> 
Yes and no. In C (and C++) you can convert a pointer to any function
type (= subprogram signature) to any other -- as long as you don't use
the result to make a call. In C++ you must convert back to the correct
signature (prototype) to make the call. 

In C only you can also use the original, pre-ANSI-89 aka K&R1, syntax
to specify pointer to function of _unspecified_ argument types but a
specified return type (including, now, void = procedure). This has the
'advantage'(?) that you can convert any pointer-to-function type to it
and vice versa _implicitly_ (without a cast).  If you call through
such a pointer the arguments are passed using (only) the fixed K&R1
rules, now called the 'default argument promotions', and you the
programmer are responsible for making sure they agree. (Which you
can't if the called function wants formals of types 'widened' by the
default promotions, namely integers below int or s-p float. Though if
you define = implement the function also using K&R1 syntax, declaring
a formal parameter of such a narrow type actually uses the widened
one, compatible with the calls.)

This allows you to create a data structure, such as a table, which has
pointers to functions of different signatures, along with some data
which allows you to determine (select) the correct signature for each
in progam logic, but not automatically checked by the compiler.

- David.Thompson1 at worldnet.att.net



      reply	other threads:[~2005-11-07  4:21 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-26 23:01 pointer questions Szymon Guz
2005-10-26 23:51 ` Gene
2005-10-26 23:58 ` tmoran
2005-10-27  1:12 ` Stephen Leake
2005-10-27  2:30 ` Steve
2005-10-27  5:56 ` Jeffrey R. Carter
2005-10-27 10:19   ` Szymon Guz
2005-10-27 14:14     ` Robert A Duff
2005-11-07  4:21       ` Dave Thompson
2005-10-27 14:11   ` Robert A Duff
2005-10-27 15:13     ` Marc A. Criley
2005-10-27 18:53       ` Jeffrey R. Carter
2005-10-27 17:29     ` Martin Dowie
2005-10-27 18:28       ` Marc A. Criley
2005-10-27 19:28         ` Martin Dowie
2005-10-28  0:12           ` Robert A Duff
2005-10-28 11:57           ` Dr. Adrian Wrigley
2005-10-28 21:26             ` Jeffrey R. Carter
2005-10-30 22:26               ` Robert A Duff
2005-10-31  6:21                 ` Jeffrey R. Carter
2005-11-02  0:52                   ` Dr. Adrian Wrigley
2005-11-02  3:46                     ` Jeffrey R. Carter
2005-11-02 11:16                       ` Dr. Adrian Wrigley
2005-11-02 13:39                     ` Robert A Duff
2005-11-02 15:34                     ` Bob Spooner
2005-11-02 18:59                     ` Björn Persson
2005-10-27 18:43     ` Jeffrey R. Carter
2005-10-28  0:42       ` Robert A Duff
2005-10-28  5:58         ` Martin Dowie
2005-10-28 21:24         ` Jeffrey R. Carter
2005-10-28 11:53     ` David
2005-10-29 12:25       ` Simon Wright
2005-10-27 17:19 ` Martin Krischik
2005-11-07  4:21   ` Dave Thompson [this message]
replies disabled

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