[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Implementation of '--' argument
From: |
avih |
Subject: |
Re: [Tinycc-devel] Implementation of '--' argument |
Date: |
Mon, 17 Apr 2023 05:59:37 +0000 (UTC) |
What some random script tries or doesn't try to do is irrelevant.
tcc should follow the spec and common practices.
Generally speaking, applications which respect the POSIX syntax
guidelines should treat non-option-argument "--" as an indication
that all further arguments are operands:
- https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
It's important to note that according to these guidelines, the
options always come before the operands. I.e. mixing of options and
operands (like GNU getopt does with permutations) is not allowed.
Therefore, the use of "--" is to indicate where the options end and
the operands start, especially for the case where the first operand
begins with "-".
"grep" should indeed respect these guidelines, and "--":
- https://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html
However, there are exceptions, for instance "echo" should not
respect these guidelines and instead treat all arguments as operands:
- https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
(the fact that some implementations of "echo" deviate from the spec
and allow options such as "-e" or "-n" is the reason for echo being
considered non portable, and why "printf" is recommended instead)
The "c99" utility, which should probably be considered the spec for
tcc, has some exceptions with regards to the syntax guidelines:
- https://pubs.opengroup.org/onlinepubs/9699919799/utilities/c99.html
While it does not specifically mention "--", it does say that
options and operands can be mixed, and some options should appear
after [c-files] operands, such as the "-l" and "-L" options
(check the synopsis).
For that reason, allowing "--" to be used before c-filenames
is a footgun, because then it's not possible to add "-l" or "-L"
options as needed by the spec.
The fact that gcc also doesn't recognize "--" is existing common
practice as well.
However, clang does recognize "--", and indeed, it rejects "-l"
or "-L" if they appear after "--" and some c-filenames.
As far as I can tell that's inconsistent with the "c99" POSIX spec.
So there you go. The main point of this is that it's not obvious
that tcc should respect "--" the same as some other utilities.
- avih
On Sunday, April 16, 2023, 11:44:24 PM GMT+3, certanan via Tinycc-devel <tinycc-devel@nongnu.org> wrote:
- [Tinycc-devel] Implementation of '--' argument, certanan, 2023/04/15
- Re: [Tinycc-devel] Implementation of '--' argument, grischka, 2023/04/16
- Re: [Tinycc-devel] Implementation of '--' argument, certanan, 2023/04/16
- Re: [Tinycc-devel] Implementation of '--' argument, Herman ten Brugge, 2023/04/16
- Re: [Tinycc-devel] Implementation of '--' argument, certanan, 2023/04/16
- Re: [Tinycc-devel] Implementation of '--' argument,
avih <=
- Re: [Tinycc-devel] Implementation of '--' argument, grischka, 2023/04/17
- Re: [Tinycc-devel] Implementation of '--' argument, ian, 2023/04/17
- Re: [Tinycc-devel] Implementation of '--' argument, certanan, 2023/04/18
- Re: [Tinycc-devel] Implementation of '--' argument, grischka, 2023/04/18
- Re: [Tinycc-devel] Implementation of '--' argument, certanan, 2023/04/18