Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Integral types and own type definitions (was Re: Suggested method for returning a string from a C program?) Date: Wed, 26 Mar 2025 15:15:09 -0700 Organization: None to speak of Lines: 38 Message-ID: <87zfh74exe.fsf@nosuchdomain.example.com> References: <86r02roqdq.fsf@linuxsc.com> <86o6xpk8sn.fsf@linuxsc.com> <20250325011327.41@kylheku.com> <20250325131110.000056bd@yahoo.com> <86bjtpjp22.fsf@linuxsc.com> <87iknw7sz8.fsf@nosuchdomain.example.com> <87sen05cza.fsf@nosuchdomain.example.com> <87o6xn60qc.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Wed, 26 Mar 2025 23:15:10 +0100 (CET) Injection-Info: dont-email.me; posting-host="469e8dc95fda8e96af14b48a4cec7ffc"; logging-data="2714274"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18R6AzMoHbgJc4QMZk1ECIu" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:ASAcqxmh0lNlKS8kmmMJQd/yF1A= sha1:XphLa6e036X+d/7y1Y7oKi48MuQ= Bytes: 3476 Janis Papanagnou writes: > On 26.03.2025 20:38, Keith Thompson wrote: [...] >> If -5 were a single token (an integer constant), then 6-5 would be an >> integer constant 6 followed by an integer constant -5, a syntax error. > > This is generally not true; that depends on the syntax rules. It is > perfectly fine to have rules for 2-ary addition and subtraction and > have also negative (and positive) literals or expressions with unary > plus and minus operators. > > Disclaimer: As usual I'm not speaking about any peculiarity that "C" > may (or may not) have defined in its standard, but generally. I suppose it would be possible to define a language syntax that makes -5 a single token and still parses 6-5 as (literal 6, binary-minus, literal-5). C is certainly not that language. If a future C standard made -5 a valid integer literal, I'm not at all sure what other changes would have to be made to avoid breaking existing code. You'll want to have both unary and binary "-" operators anyway, so you can write "-x". As long as you have a unary "-" operator, making "-5" a single token doesn't give you much -- and then you have to explain why "-x" is two tokens but "-5" is just one, or why "-5" and "- 5" are parsed differently. Note that the strto*() functions recognize strings that look like an integer constant/literal "optionally preceded by a plus or minus sign". I don't know of any language that uses "-" for both negation (prefix, one operand) and subtraction (infix, two operands) and treats -5 as a single token rather than a unary minus operator applied to the constant/literal "5". -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */