The purpose of this group is to foster exchange of information on the Texas Instruments MSP430 family of microcontrollers and related tools. Everyone welcome, all levels of familiarity/expertise.
How to get a function address in c++ - crandel_z - Oct 9 0:43:18 2009
Hi, I new with MSP430. I want to get the address of one of my program function. In
assembler I can do:
MOV #MyFunctionName,R4
in c++ ?
thx
Crandel
------------------------------------
______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.
(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )
Re: How to get a function address in c++ - Dan Bloomquist - Oct 9 1:34:39 2009
crandel_z wrote:
> Hi, I new with MSP430. I want to get the address of one of my program function. In
assembler I can do:
>
> MOV #MyFunctionName,R4
>
> in c++ ?
>
Without knowing your compiler and compliance...
Best, Dan.
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )Re: How to get a function address in c++ - crandel_z - Oct 9 3:58:47 2009
Thank you, was lack me to make the cast
WORD ptMF = (WORD)&MyFunctionName;
Crandel
--- In m...@yahoogroups.com, Dan Bloomquist
wrote:
>
> crandel_z wrote:
> > Hi, I new with MSP430. I want to get the address of one of my program function. In
assembler I can do:
> >
> > MOV #MyFunctionName,R4
> >
> > in c++ ?
> >
>
> Without knowing your compiler and compliance...
> Best, Dan.
>
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )Re: How to get a function address in c++ - Anders Lindgren - Oct 14 13:03:34 2009
crandel_z wrote:
> Hi, I new with MSP430. I want to get the address of one of my program
> function. In assembler I can do:
>
> MOV #MyFunctionName,R4
>
> in c++ ?
Hi!
Basically, there is no difference in C and C++, well, not for normal
functions that is.
Basically, writing the name of the function "foo" yields a pointer to
that function. What is tricky is getting the syntax right for the type
of the pointer. The best way to do this, in my opinion, is to define a
typedef representing a function type, then using this as the base for
the pointer type.
In the example below, "func_t" is a function type. "func_t *" is a
function pointer type. The program simply returns the address of "my_func".
---------------
typedef void func_t(void);
void my_func(void);
func_t * test()
{
return my_func;
}
---------------
On a plain MSP430, the following compiles into:
MOV.W #my_func, R12
RET
-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )
Re: How to get a function address in c++ - Franco Bucafusco - Oct 19 19:54:43 2009
Yoy may define a pointer to function type. And then, define all your
"pointed" functions using a macro.
When you need the address of the funtion is just like a variable.
funtion_pointer_type *var;
var= &function_name;
On Thu, Oct 8, 2009 at 5:13 PM, crandel_z
wrote:
> Hi, I new with MSP430. I want to get the address of one of my program
> function. In assembler I can do:
>
> MOV #MyFunctionName,R4
>
> in c++ ?
>
> thx
>
> Crandel
>
[Non-text portions of this message have been removed]
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )Re: Re: How to get a function address in c++ - 380121850 - Oct 19 21:48:09 2009
=0D
int func(int x); /* Declare a function */=0D
int (*f) (int x); /* Declare a function pointer */=0D
f=3Dfunc; /* get the function add */=0D
=0D
=0D
=0D
=0D
=0D
=0D
=0D
=B7=A2=BC=FE=C8=CB=A3=BA Franco Bucafusco =0D
=B7=A2=CB=CD=CA=B1=BC=E4=A3=BA 2009-10-20 07:54:46 =0D
=CA=D5=BC=FE=C8=CB=A3=BA msp430 =0D
=B3=AD=CB=CD=A3=BA =0D
=D6=F7=CC=E2=A3=BA Re: [msp430] How to get a function address in c++ =0D
=0D
Yoy may define a pointer to function type. And then, define all your=0D
"pointed" functions using a macro.=0D
When you need the address of the funtion is just like a variable.=0D
funtion_pointer_type *var;=0D
=0D
var=3D &function_name;=0D
=0D
On Thu, Oct 8, 2009 at 5:13 PM, crandel_z
wrote:=
=0D
=0D
>=0D
>=0D
> Hi, I new with MSP430. I want to get the address of one of my program=0D
> function. In assembler I can do:=0D
>=0D
> MOV #MyFunctionName,R4=0D
>=0D
> in c++ ?=0D
>=0D
> thx=0D
>=0D
> Crandel=0D
>=0D
> =0D
>=0D
=0D
[Non-text portions of this message have been removed]=0D
=0D
=0D
=0D
[Non-text portions of this message have been removed]
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )