address of a specific method

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
fraespre
Member
Posts: 56
Joined: Mon Aug 19, 2019 8:08 pm

address of a specific method

Post by fraespre »

How can I know the address of a specific method in runtime ?

I thought of using a function pointer. But it doesn't seem to work.
Something like this:

Code: Select all

  void my_method() {
       uint8_t option;
       option= 1;
  }
  void main() {	
	void (*methodAdr);
	methodAdr= &my_method();
        PRINT("methodAdr:", (uint16_t)methodAdr);
  } 
However the address returned is wrong.
derekfountain
Member
Posts: 121
Joined: Mon Mar 26, 2018 1:49 pm

Re: address of a specific method

Post by derekfountain »

Code: Select all

methodAdr= &my_method();
would run my_method() and give you the address of the result. I think, I'm not sure I've ever seen C code like that. :)

Code: Select all

methodAdr=my_method;
is what you're after.
fraespre
Member
Posts: 56
Joined: Mon Aug 19, 2019 8:08 pm

Re: address of a specific method

Post by fraespre »

Yeeesss , that's works perfectly !!!

Thanks a lot DerekFountain ;-)
Post Reply