gpt4 book ai didi

c - __attribute__((always_inline)) 失败

转载 作者:太空狗 更新时间:2023-10-29 15:20:14 26 4
gpt4 key购买 nike

我想知道是否有人可以阐明这一点。我得到了一个包含一些 always_inline 方法的头文件,它包含在几个地方。自从我用更新版本的 gcc 4.7.1 升级操作系统 (Debian Wheezy) 后,我收到了大量关于内联失败的警告。我能够在 gcc 4.4.5 (Debian Squeezy) 上成功编译它。我使用的编译命令是

gcc -g -Wall -O0 -o [prog_name] [sources].c -l[link libraries]

代码:

#ifndef __MCIDSHEADER_H__
#define __MCIDSHEADER_H__

#include <stdlib.h>

/* C functions */
#ifdef __cplusplus
extern "C" {
#endif

/* Constructor and destructor */
mcidsheader* mcidsheader_new(mcidsheader* obj, sqlite3* ids, crSettings* settings);
void mcidsheader_delete(mcidsheader* obj);

/* set schedule number */
__attribute__ ((always_inline)) static int mcidsheader_set_schedno(mcidsheader* obj, unsigned int var)
{
MC_CHK_OBJ(obj);
obj->var_sched_no = var;
/* memset schedule number */
memset(obj->var_sched, 0, MCIDSHEADER_SCHEDNUM_SZ);
/* copy to local */
sprintf(obj->var_sched, "%i", var);
obj->var_flg = 0;
return 0;
}

/* Get schedule number */
__attribute__ ((always_inline)) static const char* mcidsheader_get_schedno(const mcidsheader* obj)
{
MC_CHK_OBJ_PTR(obj);
return obj->var_sched;
}

/* set job number */
__attribute__ ((always_inline)) static int mcidsheader_set_jobnumber(mcidsheader* obj, const char* var)
{
MC_CHK_OBJ(obj);

/* memset buff */
memset(obj->var_jobnumber, 0, MCIDSHEADER_JOBNUMBER_SZ);
MC_CHK_OBJ(var);
/* copy to local */
strcpy(obj->var_jobnumber, var);
obj->var_flg = 0;
return 0;
}

/* get job number */
__attribute__ ((always_inline)) static const char* mcidsheader_get_jobnumber(const mcidsheader* obj)
{
MC_CHK_OBJ_PTR(obj);
return obj->var_jobnumber;
}

/* set project */
__attribute__ ((always_inline)) static int mcidsheader_set_project(mcidsheader* obj, const char* var)
{
MC_CHK_OBJ(obj);

/* memset buff */
memset(obj->var_project, 0, MCIDSHEADER_PROJECT_SZ);
MC_CHK_OBJ(var);

/* copy to local */
strcpy(obj->var_project, var);
obj->var_flg = 0;
return 0;
}

/* Get project name */
__attribute__ ((always_inline)) static const char* mcidsheader_get_project(const mcidsheader* obj)
{
MC_CHK_OBJ_PTR(obj);
return obj->var_project;
}

/* Set client */
__attribute__ ((always_inline)) static int mcidsheader_set_client(mcidsheader* obj, const char* var)
{
MC_CHK_OBJ(obj);

/* memset buff */
memset(obj->var_client, 0, MCIDSHEADER_CLIENT_SZ);
MC_CHK_OBJ(var);

/* copy to local */
strcpy(obj->var_client, var);
obj->var_flg = 0;
return 0;
}

/* get client */
__attribute__ ((always_inline)) static const char* mcidsheader_get_client(const mcidsheader* obj)
{
MC_CHK_OBJ(obj);
return obj->var_client;
}

/* set date */
__attribute__ ((always_inline)) static int mcidsheader_set_date(mcidsheader* obj, const char* var)
{
MC_CHK_OBJ(obj);
/* memset buff */
memset(obj->var_date, 0, MCIDSHEADER_DATE_SZ);
MC_CHK_OBJ(var);
/* copy to local */
strcpy(obj->var_date, var);
obj->var_flg = 0;
return 0;
}

/* get date */
__attribute__ ((always_inline)) static const char* mcidsheader_get_date(const mcidsheader* obj)
{
MC_CHK_OBJ_PTR(obj);
return obj->var_date;
}

/* Get struct size */
__attribute__ ((always_inline)) static unsigned int mcidsheader_get_size(const mcidsheader* obj)
{
if(!obj) return 0;
return obj->var_size;
}

#ifdef __cplusplus
}
#endif

#endif /* __MCIDSHEADER_H__ */

最佳答案

来自GCC manual :

GCC does not inline any functions when not optimizing unless you specify the always_inline attribute for the function, like this:

/* Prototype.  */
inline void foo (const char) __attribute__((always_inline));

因此,要解决此问题,您必须在属性前添加 inline

关于c - __attribute__((always_inline)) 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13147170/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com