inline functions

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

inline functions

1,273 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by AMJ on Fri Dec 02 22:11:36 MST 2011
inline function defined in the header file generates linker error. It seems like linker does not recognize __INLINE or just inline, and gives error saying "multiple definition". static __INLINE does not generate an error. Any idea what's going on?

Thanks
0 项奖励
回复
2 回复数

1,176 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ToBeFrank on Sun Dec 04 22:07:44 MST 2011

Quote: FlySnake
2. static means "visible only in this file". If you declare static function or variable in header, then the function will be visible in all files where this header included but as a copy of the declaration.



Ignoring the variables, since we're talking inline functions copying is irrelevant and static inline is an acceptable solution.
0 项奖励
回复

1,176 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by FlySnake on Sat Dec 03 02:06:11 MST 2011
1. Prevent multiple inclusion of the header:
#ifndef MAIN_H_
#define MAIN_H_
/* code */
#endif /* MAIN_H_ */

and  "multiple definition" will go away.
2. static means "visible only in this file". If you declare static function or variable in header, then the function will be visible in all files where this header included but as a copy of the declaration.
0 项奖励
回复