🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9602

Re: Casting void - int question

#9602
From: jnm
Date: Thu, 16 Oct 1986 00:03
50 lines
1290 bytes
Interestingly, you second example, using 
    array[1] = (int(*)())fnb;
 works fine on my machine (A Sun Workstation)...

Here is some code I wrote to achieve what you were trying to do
using alternative methods which may be useful.

I included the typedef's to make things more legible...

1.  The following program compiles ...


int fna() { }
 
void fnb() { }

typedef int (*pfi)();
typedef void (*pfv)();

pfi array[32];
main() {
    array[0] = fna;
    array[1] = (pfi)fnb;
}


2. Use Unions instead of casting ...

int fna() { }
 
void fnb() { }

typedef int (*pfi)();
typedef void (*pfv)();

struct 
{ union {
    pfi fnint;
    pfv fnvoid;
    } Union;
} array[32];
main() {
    array[0].Union.fnint = fna;
    array[1].Union.fnvoid = fnb;
}

Hope that's useful

Jonathan
sun!sunuk!jmills
Technical Details
Message-ID: <4639@brl-smoke.ARPA>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!caip!brl-adm!brl-smoke!smoke!sunuk!sunthing!jnm@Sun.COM

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!caip!brl-adm!brl-smoke!smoke!sunuk!sunthing!jnm@Sun.COM
From: jnm@Sun.COM
Newsgroups: net.lang.c
Subject: Re:  Casting void - int question
Message-ID: <4639@brl-smoke.ARPA>
Date: Wed, 15-Oct-86 20:03:56 EDT
Article-I.D.: brl-smok.4639
Posted: Wed Oct 15 20:03:56 1986
Date-Received: Tue, 21-Oct-86 21:48:59 EDT
Sender: news@brl-smoke.ARPA
Lines: 50