__attribute __((always_inline))失败

时间:2012-10-30 20:33:14

标签: c gcc

我想知道是否有人可以对此有所了解。我有一个带有几个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__ */

1 个答案:

答案 0 :(得分:9)

来自GCC manual

  

GCC不会在不优化时内联任何函数,除非您为函数指定always_inline属性,如下所示:

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

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

相关问题