From: burow@dxcern.cern.ch (Burkhard Burow)
Subject: (cast) proposal (WAS: functions as arguments in DEC C)
Organization: CERN European Laboratory for Particle Physics
Date: Tue, 26 Jan 1993 13:52:14 GMT


In article <1993Jan23.211019.6955@dxcern.cern.ch>,
I asked how one could cast a pointer to a function, say 'void ( *a)()',
to a "generic pointer to a function" which could be passed
as an argument to a function expecting a pointer to a function, 
say 'int  ( *c)()' in the prototype.

Note: I don't wish or need to cast pointers to objects to pointers to functions,
      or vice versa.
and
      I wish to benefit as much as possible from function prototyping.

CONSTRAINT:
My application doesn't know that 'int  ( *c)()' is expected, it just knows
that a pointer to a function is expected.

I thank all those that replied, but unfortunately, my original posting didn't
make the above CONSTRAINT clear enough, so most of the replies told me to do:

 (int (*)())a

My application can't do '(int (*)())a' because it doesn't know that a pointer
to a function returning int is expected.
It just knows that a pointer to function is expected.

In my followup <1993Jan24.094945.7767@dxcern.cern.ch>, I emphasized
the constraint and explained why my application has this constraint.

My followup was followed by <C1DCr5.2v1@micrognosis.co.uk>, nreadwin@micrognosis.co.uk (Neil Readwin)
-|>That's why I need a cast for saying:
-|> 'This is a pointer to a function.
-|>  I don't give a flying f*** about the type of argument the function returns.'
- 
-Having spent a little time reading through both the standard and the Rationale
-(especially 3.2.2.3), I do not think that ANSI C provides this. This came as
-something of a surprise to me.

RFC: Why doesn't ANSI C provide this?

In a similar vein:

QQQQuestion: Does C provide a cast, other than (void *) to do the following?

#include <stdlib.h>

void f(int a[3][5]) { a[0][0] = 1; return; }

typedef ?????  CAST;

void g(int *b)
{
f( (CAST) b);
}

CONSTAINT:
My application, generating the intermediate function g,
knows the type of the array 'b',     in this case 'int',
and the number of dimensions of 'b', in this case 2
but it doesn't know the size of the individual dimensions, here 3 and 5.

EMBARRASSMENT:
I must admit that I can't make the cast for 'b' even if I do use the size of
the individual dimensions, though I don't understand why ANSI C wouldn't like
it.
gcc complains 'cast specifies array type' as soon as I have [] inside a cast.
Clarifications/Justifications sought.

QQQuestion/PPProposal:
Why doesn't C allow 'incomplete casting' in order to allow one to best match
the prototyping of the arguments of functions?
e.g.
i)   pointer to function >cast> pointer to function returning void or any type:
     ((*)())

ii)  pointer to object   >cast> address of 2D array of ints:
     (int [][])

iii) pointer             >cast> cast as required by the function prototype
     ()

My application needs i) and ii). [iii) might be fun though.]

At the moment ANSI C allows only 'perfect casting' or the brute force 'void',
i) and ii) would allow one to cast with as much info. as one has.

Thanks again to all those taking an interest in my plight,
especially to those who sent me a reply.

burkhard,       burow@vxdesy.cern.ch
Newsgroups: comp.lang.c