On 20/12/2018 20:05, Rick C. Hodgin wrote:
> On 12/20/2018 1:59 PM, Bart wrote:
>> On 20/12/2018 18:39, Rick C. Hodgin wrote:
>>> On 12/20/2018 12:57 PM, James Kuyper wrote:
>>>> On Thursday, December 20, 2018 at 12:44:37 PM UTC-5, Rick C. Hodgin
>>>> wrote:
>>>>> ~~ would be a separate token from ~(~x) as it is today. It would be
>>>>> like + and ++.
>>>>
>>>> What does "as it is today" refer to? "~~" is NOT a separate token
>>>> today. It parses as two consecutive "~" tokens.
>>>
>>> I am not aware of that operator as two consecutive ~~ characters. I
>>> did a search for it for C or C++ and didn't find it. Only the single
>>> ~ character.
>>>
>>> What does ~~ do today?
>>>
>>> And if the syntax it uses today is different than the syntax that I
>>> propose, such that there is no legal use of ~~ in the syntax I pro-
>>> pose today, then why would it matter? It would be parsed as two dif-
>>> ferent uses of the same operator, like << and << for one use to bit
>>> shift, one use to direct / pipe as with cout.
>>>
>>
>> !! is often used, but !! is two ! tokens one after the other.
>
> I've seen that before and I've seen it's been explained here, but I
> still don't know what it does. I've seen it in Linux source code.
>
!! is two ! tokens after each other. !x turns 0 into 1, and non-zero
into 0. So applying that twice, means !!x turns 0 into 0, and non-zero
into 1. So in usage, !!x means "normalise x as a 0/1 boolean value".
It is not often necessary in C99, where you have proper booleans, and
was more common in C90 code. I've used it a few times myself.
>> You proposal would either mean processing ~~ as one new brand-new
>> token, or introducing a new binary operator that consists of two ~
>> tokens.
>
> I still don't see where ~~ is an operator. I'd like to see a project
> that uses that functionality. I find Javascript references to it
> online, but none for C or C++.
~~ is not an operator - it is two operators, after each other.
The issue here is not that someone might intentionally use ~~ (though it
might turn up due to macros). Nor will you find any code that looks
like "a~~b", as it would be a syntax error (unless "a" is a macro of
some sort).
The issue is the way C defines the rules for parsing and lexical
analysis. If you want a set of characters to be treated as a single
token - such as "~~" - then it will /always/ be treated as that token.
That is fine for your new use, for "a~~b". And the old "~" operator
will usually work as before - "x = ~y".
However, if someone were to write "x = ~~y;", then in normal C this will
be treated as "x = ~(~y);" because there is no "~~" token. With your
extension, it would now be parsed as "x" "assignment operator"
"shorthand pointer operator" "y". That would be meaningless, but code
that used to be valid C is now invalid.
Does this actually matter? Probably not, in this case - you are
unlikely ever to come across C code like "x = ~~y;", even allowing for
odd macros. I don't think it should stop you using this operator. (I
don't like the operator suggestion for other reasons, but that is beside
the point here.)
C++ had to deal with this situation when trying to allow ">>" to be the
same as "> >" for closing two template declarations. It was
surprisingly difficult, and broke the way tokenising worked, but it
neatened the language for users.
If your CAlive language has a different kind of parsing and tokenising,
then only you can tell if it is a problem or not. In these groups, we
can only tell you how it relates to C and C++.
>
> Show me where it's used in SQLite, or Blender or some open source
> software of significance.
>
Almost certainly never, which is why I would say it is only a
theoretical issue and should not stop you. But you ought to understand
the issue so that you can make an informed decision.