__attribute__ ((__pure__))

#include <stdio.h>

#if __GNUC_PREREQ (2,96)
# define _pure __attribute__ ((__pure__))
#else
# define _pure
#endif

//这个函数这个函数没有副作用,当不需要它的返回值时,它可以被优化掉,
int _pure func1()
{
	printf("func1 pure test.\n");
}

int func2()
{
	printf("func2 pure test.\n");
}

int main()
{
	func1();

	int a = func1();

	func2();

	return 0;
}
# ./a.out 
func1 pure test.
func2 pure test.
发布了554 篇原创文章 · 获赞 269 · 访问量 48万+

猜你喜欢

转载自blog.csdn.net/Rong_Toa/article/details/104063368