遇到的编译错误或警告(小集锦)

这篇博客汇总了在编程过程中遇到的两种主要问题——错误和警告。错误包括'返回类型是不完整的类型',通常是由于在定义函数返回类型时未完整指定结构体。警告部分未详述。此外,提到了编码规范的重要性,如结构体指针声明时应初始化为NULL,以避免不同编译器导致的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一 错误

1、error: return type is an incomplete type

翻译过来是:返回类型是不完整的类型。

我这里出现的原因是,在写函数接口的时候,返回的是结构体指针,但是在定义函数返回类型的时候,只写了对应的结构体。

错误代码如下:

 

struct SwrContext swr_config(struct SwrContext *s, AVFormatContext *ic, S32 stream_index)
{
    if(NULL == s)
    {
        s = swr_alloc();
    }
    s = swr_alloc_set_opts(s,          // we're allocating a new context
            AV_CH_LAYOUT_STEREO,  // out_ch_layout
            AV_SAMPLE_FMT_S32,      // out_sample_fmt
            SWR_SAMPLE_RATE,      // out_sample_rate
            ic->streams[stream_index]->codec->channel_layout,    // in_ch_layout
            ic->streams[stream_index]->codec->sample_fmt,        // in_sample_fmt
            ic->streams[stream_index]->codec->sample_rate,       // in_sample_rate
            0,                      // log_offset
            NULL);                  // log_ctx
    swr_init(s);

    return s;
}

 

 


 

错误提示为:

decoder1.c:52:19: error: return type is an incomplete type struct SwrContext swr_config(struct SwrContext *s, AVFormatContext *ic, S32 stream_index)                   ^decoder1.c: In function ‘swr_config’:decoder1.c:69:9: warning: ‘return’ with a value, in function returning void  return s;

更改后的代码为:

 

struct SwrContext *swr_config(struct SwrContext *s, AVFormatContext *ic, S32 stream_index)
{
    if(NULL == s)
    {
        s = swr_alloc();
    }
    s = swr_alloc_set_opts(s,          // we're allocating a new context
            AV_CH_LAYOUT_STEREO,  // out_ch_layout
            AV_SAMPLE_FMT_S32,      // out_sample_fmt
            SWR_SAMPLE_RATE,      // out_sample_rate
            ic->streams[stream_index]->codec->channel_layout,    // in_ch_layout
            ic->streams[stream_index]->codec->sample_fmt,        // in_sample_fmt
            ic->streams[stream_index]->codec->sample_rate,       // in_sample_rate
            0,                      // log_offset
            NULL);                  // log_ctx
    swr_init(s);

    return s;
}

 

2、unrecognized argument in option ‘mcmode=kernel’

在编译内核驱动时,报该错误

通过在编译命令 增加option ARCH=arm 解决

 

二 警告

 

三 编码规范

NOTE:这里的编码规范是指,如果不按照,有时就回出现错误

1 结构体指针在声明的时候,必须赋为NULL。

原因:如果不赋为NULL,不同的编译器在处理结构体声明的时候,有的会自动赋为空,有的会赋一个值(影响申请内存的过程)。

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值