Board index » delphi » Assign functions to function pointers

Assign functions to function pointers

I'd like to assign Delphi's built-in functions like "sin" to function
pointers.

Example :

Type TFunction = Function(x : Extended) : Extended;

VAR f : TFunction;

BEGIN
  f := @sin;
  ...
END;

However I get a compile error saying, that a '(' is expected instead
of a ';'.  When I try to do this with a self-written function, this
approach works perfectly. It's just Delphis own functions that won't
do it.

How do they differ from self-written functions ? How can I reach my
goal ? Of course I could write a wrapper function for "sin", but I'd
like to avoid that.

Please send any comments, hints, proposals to

mailto:Rudi.Zieg...@bingo.baynet.de

since I don't read this newsgroup regularly,

Thanks,

Rudi

 

Re:Assign functions to function pointers


In article <35b9dc83.60627...@news.bingo.baynet.de>,
  Rudi.Zieg...@bingo.baynet.de (Rudi Ziegaus) wrote:

Quote
> I'd like to assign Delphi's built-in functions like "sin" to function
> pointers.

> Example :

> Type TFunction = Function(x : Extended) : Extended;

> VAR f : TFunction;

> BEGIN
>   f := @sin;
>   ...
> END;

> However I get a compile error saying, that a '(' is expected instead
> of a ';'.  When I try to do this with a self-written function, this
> approach works perfectly. It's just Delphis own functions that won't
> do it.

> How do they differ from self-written functions ?

        I wouldn't know about the details, but at least in some
cases calls to standard procedures are simply not compiled as
ordinary function calls - they're compiled inline, or they're
compiled as calls to this function or that function depending
on the arguments, etc. So there simply is no "function" to
take the address of.

Quote
> How can I reach my
> goal ?

      Well you could write a wrapper function.

Quote
> Of course I could write a wrapper function for "sin", but I'd
> like to avoid that.

      Or not.

     (Please check the newsgroup for replies, as I don't send
email regularly.)

David C. Ullrich

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

Re:Assign functions to function pointers


Quote
Rudi Ziegaus wrote:
> I'd like to assign Delphi's built-in functions like "sin" to function
> pointers.

The sin function is defined in the system unit.  Many of the functions
defined this unit are "special" in that they are really compiler magic
rather than actual functions.  In the case of sin, the actual thing that
is called is an ASM procedure (not a function) called "_SIN".  It's
possible that you could get the address of this proc and use it, but the
safe thing to do would be to go the wrapper route.

Bob Lee

Re:Assign functions to function pointers


In article <35b9dc83.60627...@news.bingo.baynet.de>,

Quote
Rudi.Zieg...@bingo.baynet.de (Rudi Ziegaus) writes:
>However I get a compile error saying, that a '(' is expected instead
>of a ';'.  When I try to do this with a self-written function, this
>approach works perfectly. It's just Delphis own functions that won't
>do it.

Try redeclaring the sin function in your own unit. Let me know what happens

Charles Johnson

Other Threads