processHiddens = false; options --6ren">
gpt4 book ai didi

c - 为什么我收到 "statement with no effect"警告?

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

下面是我的代码

/* Initialise default without options input. */
options -> processHiddens = false;
options -> timeResolution = DEFAULT_MOD_TIMES;
options -> performSync = true;
options -> recursive = false;
options -> print = false;
options -> updateStatus = true;
options -> verbose = false;
options -> programname = malloc(BUFSIZ);
options -> programname = argv[0];

while ((opt = getopt(argc, argv, OPTLIST)) != -1)
{
switch (opt)
{
case 'a':
!(options -> processHiddens);
case 'm':
options -> timeResolution = atoi(optarg);
case 'n':
!(options -> performSync);
case 'p':
!(options -> print);
case 'r':
!(options -> recursive);
case 'u':
!(options -> updateStatus);
case 'v':
!(options -> verbose);
default:
argc = -1;
}
}

我想做的是在每次输入选项时翻转 bool 语句,因此做类似的事情

!(options -> processHiddens);

不仅仅是

options -> processHiddens = true;

但是我在编译时收到以下警告:

mysync.c: In function ‘main’:
mysync.c:32: warning: statement with no effect
mysync.c:36: warning: statement with no effect
mysync.c:38: warning: statement with no effect
mysync.c:40: warning: statement with no effect
mysync.c:42: warning: statement with no effect
mysync.c:44: warning: statement with no effect

最佳答案

因为 !(options -> processHiddens) 是一个表达式,并且您没有将结果分配给任何东西。你需要这样的东西:

options->processHiddens = !options->processHiddens;

关于c - 为什么我收到 "statement with no effect"警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4007884/

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