...另一方面,如果我在打开下一个管道之前写了一些东西,这不会发生.
以下代码应该更清楚:
sub test_concurrent_pipes
{
my $write_at_once = $_[0];
my $pipe_handle;
my @pipe_handle_list;
my $i;
foreach $i ( 1..3 )
{
open ( $pipe_handle, "| xargs echo" ) or die ( "Cannot open pipe.\n" );
if ( $write_at_once == 1 )
{
print $pipe_handle "Hello\n";
}
push( @pipe_handle_list, $pipe_handle );
}
foreach $pipe_handle ( @pipe_handle_list )
{
print $pipe_handle "world\n";
}
foreach $pipe_handle ( @pipe_handle_list )
{
close ( $pipe_handle );
}
}
print "Test 0: open all pipes before …Run Code Online (Sandbox Code Playgroud) 可能是受 Perl 的影响,我喜欢使用下面的语法
condition && do_something();
Run Code Online (Sandbox Code Playgroud)
代替
if ( condition )
{
do_something();
}
Run Code Online (Sandbox Code Playgroud)
(我知道我可以在没有大括号的情况下将后者放在一行中,但这不是重点。)
我已经进行了几次测试(如下),这些测试有效。但是我在标准中找不到参考,说明它是合法的。它可以隐含在
但我不完全确定(我检查了 C++ 98,抱歉是老式的,但可能甚至 C 标准就足够了)。
注意:我确实意识到为了工作,最后一个表达式 (do_something) 也必须可以转换为 bool,这对于选择语句来说不是必需的。这当然是一个严重的限制。
所以问题是:
抱歉,如果结果是重复的,我找不到任何东西,但可能是因为我没有使用正确的关键字。
#include <cassert>
bool sayYes()
{
return true;
}
bool sayNo()
{
return false;
}
int main( int args, char* argv[] )
{
bool a = true;
bool b = false;
int i = 0;
a && ( i = 1 );
assert( i == …Run Code Online (Sandbox Code Playgroud)