开发者

restriction on using #define'd functions/inline functions inside Assembly files

Is there any restriction on using #define'd functions/inline functions inside Assembly files.

I referred bsd kernel in which two different implementations are defined. One is macro and other is a normal function ( both are for same function)

In the c file splx is defined asfunction, http://ftp.hu.freebsd.org/pub/netbsd/NetBSD-release-4-0/src/sys/arch/arm/omap/omap_intr.c

Whereas in h header file splx is defined as macro, http://ftp.hu.freebsd.org/pub/netbsd/NetBSD-release-4-0/src/sys/arch/arm/omap/omap_intr.h

My understanding is c file definition is used in assembly files whereas macro definition is used in all other functions where the header file is included.

I think I m not clear why assembly is coming into picture here. Basically there are two definitions , one in the c file and another in h file for splx. When I just comment out splx definition in C fle, I get some errors in the compilation 开发者_StackOverflowof Assembly files.(cpu.S) Thatz why I thought function definition is used(as in c file) while compiling assembly file, whereas macro definition is used for all other files include the h file.

Now my question is: Why can't assembly file too cannot use the macro definition by including the header file?


In the header file, splx is defined as

void splx(int)
void _setsoftintr(int);

#if !defined(EVBARM_SPL_NOINLINE)
#define splx(new) omap_splx(new)
#define _spllower(ipl) omap_spllower(ipl)
#define _setsoftintr(si) omap_setsoftintr(si)
#endif /* !EVBARM_SPL_NOINTR */ 

I'm not sure why you're referring to assembly files when this language is clearly C, but I see nothing wrong with these declarations - splx is a function, but if EVBARM_SPL_NOINLINE is defined then the macro is used to remap all uses of splx to splx_omap. This is a valid use of the preprocessor, and is not redefining splx - rather using some trickery to modify code to use splx_omap.

This works because the preprocessor runs before the compiler, so any occurence of splx will be replaced by splx_omap before compilation takes place. Some people would find this disturbing but it's one of the capabilities of the preprocessor and is quite useful (when proper precautions are observed).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜