编译警告"struct declared inside parameter list"

近来在阅读linux-2.6.37中cgroup的相关代码,读到include/linux/cgroup.h的开头时犯了嘀咕:

 

#include <linux/sched.h>
#include <linux/cpumask.h>
#include <linux/nodemask.h>
#include <linux/rcupdate.h>
#include <linux/cgroupstats.h>
#include <linux/prio_heap.h>
#include <linux/rwsem.h>
#include <linux/idr.h>

#ifdef CONFIG_CGROUPS

struct cgroupfs_root;
struct cgroup_subsys;
struct inode;
struct cgroup;
struct css_id;

extern int cgroup_init_early(void);
extern int cgroup_init(void);
extern void cgroup_lock(void);

extern int cgroup_lock_is_held(void);
extern bool cgroup_lock_live_group (struct cgroup *cgrp);

......

 

在此头文件的后面有cgroupfs_root、cgroup_subsys、cgroup这三个结构的定义,为何此处需要这么几行代码?

 

将此处的"strct cgroup;“注释掉之后,重新编译内核报出如下错误和警告:

 

kernel/cgroup.c:1910: error: conflicting types for ‘cgroup_lock_live_group’
include/linux/cgroup.h:32: error: previous declaration of ‘cgroup_lock_live_group’ was here
kernel/cgroup.c:1918: error: conflicting types for ‘cgroup_lock_live_group’
include/linux/cgroup.h:32: error: previous declaration of ‘cgroup_lock_live_group’ was here

 

include/linux/cgroup.h:32: warning: ‘struct cgroup’ declared inside parameter list
include/linux/cgroup.h:32: warning: its scope is only this definition or declaration, which is probably not what you want

 

由此我们可以知道,由于在cgroup.h文件中,struct cgroup结构定义在函数声明

extern bool cgroup_lock_live_group (struct cgroup *cgrp);

之后,所以编译的时候将struct cgroup作为在参数列表中定义的空结构处理了,这样在编译cgroup.c的时候便与真实的cgroup_lock_live_group函数定义冲突。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值