Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在拼命寻找一种方法来轻松计算 C 函数中所有可能的执行路径的数量。
例如,对于以下函数,我希望得到 3 的结果(如果有机会基于 'i' 进入任何 'if' 语句的值)
void test(void) { if (i>0) x = x + 1; else if (i>10) x = x + 2; else x = x + 3; }
使用逗号运算符作为
int test(void) { int ways = 0; if (++ways, i>0) x = x + 1; else if (++ways, i>10) x = x + 2; else { x = x + 3; ++ways; } return ways; }