gpt4 book ai didi

c - 如何解决 "expected expression before ' unsigned'"错误?

转载 作者:太空宇宙 更新时间:2023-11-04 05:44:46 24 4
gpt4 key购买 nike

我的代码是:

#include <unistd.h>  

(void)alarm(unsigned int 0);

error: expected expression before 'unsigned'

但我收到以下错误:

Error: expected expression before 'unsigned', due to: (void)alarm(unsigned int 0);

我不确定这是我的语法还是使用了 (void) 还是别的什么。怎么回事?

我正在使用 Code::Blocks在 Windows 下。

最佳答案

呃,这是一个函数调用,还是一个声明?

如果你的意思是声明,那么它应该是:

void alarm( unsigned int i );

如果你的意思是它是一个函数调用,那么它应该是:

(void) alarm( 0 );

(在我使用 C++ 的日子里,当我想记录一个我不关心函数返回什么的事实时,我常常将函数结果转换为 void。)

编辑:再说一遍,如果您要做的只是声明一个变量,那么试试这个:

unsigned int alarm = 0;

或者,如果您只是想将变量设置为零,那么事情就更简单了:

alarm = 0;

8-)

关于c - 如何解决 "expected expression before ' unsigned'"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8583017/

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