error: ISO C90 forbids mixed declarations and code

在进行linux 的audio驱动开发过程中,遇到一个问题。编译时总是提示出错。最后问题得以解决,但是查看其他驱动模块,按照图1这种写法不会出错,很大可能性是对编译器设置的代码检查规则不一样。 

error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
  struct vad_regs *vad_regs_p=kmalloc(sizeof(struct vad_regs), GFP_KERNEL );
Linux内核编程中遇到的问题,意思是声明和代码不能写在一起 

	struct aml_audio_vad *pvad = fp->private_data;
	struct platform_device *pdev = to_platform_device(s_vad->dev);
	
	void __user *argp = (void __user *)arg;
	int ret = 0;
	size_t len;
	if(!pvad)
		pr_err("%s error: file->private_data is null, \
				open file before do ioctl\n", __func__);
	
	struct vad_regs *vad_regs_p=kmalloc(sizeof(struct vad_regs), GFP_KERNEL );

编译出错:

修改后

	struct aml_audio_vad *pvad = fp->private_data;
	struct platform_device *pdev = to_platform_device(s_vad->dev);
	struct vad_regs *vad_regs_p;
	void __user *argp = (void __user *)arg;
	int ret = 0;
	size_t len;
	if(!pvad)
		pr_err("%s error: file->private_data is null, \
				open file before do ioctl\n", __func__);
	
	vad_regs_p=kmalloc(sizeof(struct vad_regs), GFP_KERNEL );

 

你可能感兴趣的:(C语言)