简体   繁体   中英

What does this C macro do?

do you know what does this code mean?

#define StartEsub (unsigned short   (**) (unsigned short \
                                               AnalogConfigReg, \
                                               unsigned short \
                                               AnalogClockMask)) 0x00502501

Get rid of the messy macro and you get

(unsigned short (**) (unsigned short AnalogConfigReg, 
                      unsigned short AnalogClockMask)) 0x00502501

Which is a cast from an integer, representing an address, into a pointer to a function pointer. How a pointer to a function pointer is meaningful for your specific case, I have no idea.

A much better and more readable way to write the same would be:

typedef unsigned short func_t (unsigned short AnalogConfigReg, 
                               unsigned short AnalogClockMask);

(func_t**) 0x00502501

It seems to be defining a hard-coded vector address for a function (a pointer to a function pointer). It will be specific to your particular embedded target, so you might want to add details about the system where this code is being used.

In more detail - there is apparently a function somewhere that looks like this:

unsigned short foo (unsigned short AnalogConfigReg,
                    unsigned short AnalogClockMask)

and a pointer to this function is stored at the address 0x00502501 .

This kind of thing is sometimes known as a "hook", and it probably allows a user-defined function to be installed by modifying this hook address.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM