Re: Ill-behaved `gcc -E ... | head` exit status?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2021-04-29 at 22:09 -0500, Peng Yu via Gcc-help wrote:
> $ gcc -E - <<< '#include <stdio.h>' | head -n 1
> # 1 "<stdin>"
> $ declare -p PIPESTATUS
> declare -a PIPESTATUS=([0]="2" [1]="0")
> $ gcc --version
> gcc (Debian 10.2.1-6) 10.2.1 20210110
> Copyright (C) 2020 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.
> 
> gcc returns 2 in the above example. This does not follow the standard
> convention on Linux.
> 
> For example, the exit status of seq is 141 which corresponds to a
> SIGPIPE signal.
> 
> $ seq 1000000 | head -n 1
> 1
> $ declare -p PIPESTATUS
> declare -a PIPESTATUS=([0]="141" [1]="0")
> 
> Should gcc conform to this standard as well? Thanks.
> 

I don't think 141 is a "standard".  And I can't find it in POSIX or LSB.

POSIX 2017 Volumn "Shell & Utilities" section 1.4:

> In some cases, status values are listed more loosely, such as >0. A
> strictly conforming application shall not rely on any specific value in
> the range shown and shall be prepared to receive any value in the range.

And section 4 specified a C compiler named c99, where the exit status is
said to be:

> EXIT STATUS
> 
> The following exit values shall be returned:
> 
>  0
> Successful compilation or link edit.
> >0
> An error occurred.

So POSIX specifies that a C compiler can return anything > 0 for an
error occurred.

If you see an authoritive standard document saying "a C compiler should
return 141 when pipe is broken", then report to
https://gcc.gnu.org/bugzilla and put the URL of the standard document in
the report.
-- 
Xi Ruoyao <xry111@xxxxxxxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux