我在C ++中得到了这个警告。我猜想。
当我尝试使用g ++构建我的程序时
g++ --version
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
file.cpp: In function âvoid mainloop(THREAD_DATA*)â:
file.cpp:970: warning: statement has no effect
typedef
struct THREAD_DATA_
{
struct spectate_player_t {
bool want_updates; /* want player updates by specating all players every 100 milliseconds (who are in ship of course) */
PLAYER *last_spec_player; /* last spectated player (just so it knows where it left off) */
bool direction; /* which direction spectating goes (used to avoid dead ends) so it cycles all players */
} spectate[1];
} THREAD_DATA;
...
static void mainloop(THREAD_DATA *td)
第970行只是一个我曾经认为在C ++中一直工作的切换,所以它让我感到困惑,为什么它突然被删除或者警告没用?
Line 967: if(td->spectate->last_spec_player)
Line 968: pkt_send_spectate_player(td->spectate->last_spec_player->pid);
Line 969: else
Line 970: td->spectate->direction != td->spectate->direction;
答案 0 :(得分:5)
它应该是:
td->spectate->direction = !td->spectate->direction;
由于!=
是不等式运算符,a != a
不等于a = !a
,它等于!(a == a)