🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4496

Re: generic pointer to function

#4496
From: Lawrence Kirby
Date: Sun, 17 Dec 1995 01:26
30 lines
1621 bytes
In article <Dominique.Marcadet-1212951916480001@marcadet.supelec.fr>
           Dominique.Marcadet@supelec.fr "Dominique Marcadet" writes:

>Here is another question on Standard C (sorry, I don't have the standard).
>
>I think I have read in a previous thread that void * was not compatible
>with pointer to function. Then, is there any way to have a generic pointer
>to function, so that I may write in a standard way :

Not in the sense that conversions to and from the type can happen implicitly
(i.e. without a cast).

...

>If not, are all pointers to functions compatible one with another ? that
>is, does this code is valid :
>
>typedef void (*generic_pointer_to_function)(void);
>
>is_null_function ((generic_pointer_to_function) &printf);
>is_null_function ((generic_pointer_to_function) &scanf);

Yes, this is valid. As always you have to cast the function pointer back
to the correct type before you dereference it (i.e. call the function).

-- 
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
Technical Details
Message-ID: <819163560snz@genesis.demon.co.uk>
Path: arc1-ca.pugleaf.net!mail2news.demon.co.uk!genesis.demon.co.uk
References: <Dominique.Marcadet-1212951916480001@marcadet.supelec.fr>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!mail2news.demon.co.uk!genesis.demon.co.uk
From: Lawrence Kirby <fred@genesis.demon.co.uk>
Newsgroups: comp.std.c
Subject: Re: generic pointer to function
Date: Sun, 17 Dec 95 01:26:00 GMT
Organization: none
Message-ID: <819163560snz@genesis.demon.co.uk>
References: <Dominique.Marcadet-1212951916480001@marcadet.supelec.fr>
Reply-To: fred@genesis.demon.co.uk
X-NNTP-Posting-Host: genesis.demon.co.uk
X-Newsreader: Demon Internet Simple News v1.27