jon*_*hua 0 c structure compiler-warnings
以下是我的代码
/* 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;
}
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是每次输入一个选项时都要翻转布尔语句,因此做类似的事情
!(options -> processHiddens);
Run Code Online (Sandbox Code Playgroud)
而不仅仅是
options -> processHiddens = true;
Run Code Online (Sandbox Code Playgroud)
但是在编译时我收到以下警告:
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
Run Code Online (Sandbox Code Playgroud)
Oli*_*rth 12
因为!(options -> processHiddens)是表达式,并且您没有将结果分配给任何东西.你需要这样的东西:
options->processHiddens = !options->processHiddens;
Run Code Online (Sandbox Code Playgroud)
因为!(options -> processHiddens);"和"一样" 40 + 2.它真的没有效果:-)
printf("foo");
40 + 2;
printf("bar");
Run Code Online (Sandbox Code Playgroud)
你要
option -> processHiddens = !(options -> processHiddens);
break; /* without break, all the following lines will execute */
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12341 次 |
| 最近记录: |