April 01, 2019
On Monday, 1 April 2019 at 13:57:17 UTC, Atila Neves wrote:
> On Monday, 1 April 2019 at 13:09:28 UTC, Dein wrote:
>> On Monday, 1 April 2019 at 01:18:44 UTC, Walter Bright wrote:
>>> On 3/31/2019 5:35 PM, Rubn wrote:
>>>> you can literally use it everywhere else you can use a type.
>>>
>>> No, you can't. An array of refs won't compile, either.
>>>
>>>   void test(int& a[]); // error
>>>
>>> A C++ ref can only appear at the top of a type AST, which is unlike any other type. Which exactly matches the only place a storage class can be!
>>
>> Seriously? You should know as well as I do what that function actually translates to:
>>
>>    void test(int&* const a);
>>
>> So I ask you now, how do you get a pointer to a reference. Its the exact same thing. Not sure if you are trying to just deceive me with some syntax sugar in C++ or what.
>
> Bad example, but the point stands:
>
>
> ----
> // foo.cpp
> int fun() {
>     int& foo[5]; // doesn't compile
> }
> ----
>
> I'd never even thought of it until Walter mentioned it that one can't have an array of references. Huh.

Arrays in C++ are just pointers. If you can't have a pointer to something, it is only natural you can't have array either.

    void* ptr;   // ok
    void arr[5]; // error

So I guess Walter agrees that void isn't a type then right? You can't have an array to it so that's the deciding factor.
April 01, 2019
On 4/1/2019 6:09 AM, Dein wrote:
> Not sure if you are trying to just deceive me with some syntax sugar in C++ or what.

You can try it yourself:

----------
g++ -c test.cpp
test.cpp:1:17: error: cannot declare pointer to int&
 void test(int&* p);
                 ^
----------
 g++ -c test.cpp
test.cpp:1:18: error: declaration of p as array of references
 void test(int& p[]);
                  ^
----------
April 01, 2019
On 4/1/2019 1:00 PM, Rubn wrote:
> Arrays in C++ are just pointers.

No, they're not.


> If you can't have a pointer to something, it is only natural you can't have array either.

g++ -c test.cpp
test.cpp: In function void test():
test.cpp:1:24: error: declaration of p as array of references
 void test() {  int& p[3]; }
                        ^

As I said, C++ ref can only appear at the top of an AST, which is what a "storage class" is.

C++ tries to have it be both a floor wax and a desert topping, making for a device that nobody understands. Be careful what you wish for.
April 01, 2019
On Monday, 1 April 2019 at 20:00:34 UTC, Rubn wrote:
> On Monday, 1 April 2019 at 13:57:17 UTC, Atila Neves wrote:
>> On Monday, 1 April 2019 at 13:09:28 UTC, Dein wrote:
>>> On Monday, 1 April 2019 at 01:18:44 UTC, Walter Bright wrote:
>>>> On 3/31/2019 5:35 PM, Rubn wrote:
>>>>> you can literally use it everywhere else you can use a type.
>>>>
>>>> No, you can't. An array of refs won't compile, either.
>>>>
>>>>   void test(int& a[]); // error
>>>>
>>>> A C++ ref can only appear at the top of a type AST, which is unlike any other type. Which exactly matches the only place a storage class can be!
>>>
>>> Seriously? You should know as well as I do what that function actually translates to:
>>>
>>>    void test(int&* const a);
>>>
>>> So I ask you now, how do you get a pointer to a reference. Its the exact same thing. Not sure if you are trying to just deceive me with some syntax sugar in C++ or what.
>>
>> Bad example, but the point stands:
>>
>>
>> ----
>> // foo.cpp
>> int fun() {
>>     int& foo[5]; // doesn't compile
>> }
>> ----
>>
>> I'd never even thought of it until Walter mentioned it that one can't have an array of references. Huh.
>
> Arrays in C++ are just pointers. If you can't have a pointer to something, it is only natural you can't have array either.

Arrays in C (and by extension C++) are most definitely not "just pointers". This is a common misconception due to arrays decaying to pointers in function calls. There are such things as array pointers in C, and C++ adds array references to the mix for, in all likelihood, consistency. I haven't met many C programmers that know of their existence.


>     void* ptr;   // ok
>     void arr[5]; // error
>
> So I guess Walter agrees that void isn't a type then right? You can't have an array to it so that's the deciding factor.

Funnily enough your example here shows how pointers and arrays aren't the same thing. The reason you can't have an array of "voids" in C is because void has no size and the whole thing is nonsensical. It's a good point though that void is treated differently in C's type system.


April 01, 2019
On Friday, 29 March 2019 at 16:06:09 UTC, Victor Porton wrote:
> That `ref T` (where T is a type) is not a type is a serious design error,

No.

> It is a very serious problem.

No.

> Can the language be changed to resolve this problem?

There is no reason to do so.
April 01, 2019
On Monday, 1 April 2019 at 11:09:01 UTC, Walter Bright wrote:
> If I may, I once talked to a Ferrari mechanic. He said that most engines inside, where customers didn't see the innards, were sloppily made. But that the Ferrari engine was a thing of beauty inside and a joy to work on. Ironically, Ferraris are also known for cheap, poorly done cab interiors. An unusual focus for a car company :-) but one that appeals to my inner engineer. The engine in my Dodge was built the same way, it's blueprinted with all top quality parts inside it, but the outside is plain jane, no chrome parts, no dress-up, etc.

So your mechanic friend is comparing hand-built and individually tuned super-sport performance Ferraris to mass produced production-line commuter cars? When you don't have to focus on practicality with an inflated price tag you aren't limited with how you design your vehicle. You will be overpaying for maintenance costs though.

I really doubt your Dodge engine was built the same way as a Ferrari's was unless maybe you are driving around a Dodge Viper. Please tell me your not one of those people that drive around a truck. American brand vehicles (yes not only cars) aren't well known for their reliability either.
April 01, 2019
On Monday, 1 April 2019 at 20:37:03 UTC, Walter Bright wrote:
> On 4/1/2019 6:09 AM, Dein wrote:
>> Not sure if you are trying to just deceive me with some syntax sugar in C++ or what.
>
> You can try it yourself:
>
> ----------
> g++ -c test.cpp
> test.cpp:1:17: error: cannot declare pointer to int&
>  void test(int&* p);
>                  ^
> ----------
>  g++ -c test.cpp
> test.cpp:1:18: error: declaration of p as array of references
>  void test(int& p[]);
>                   ^
> ----------

You can try it yourself:

void foo(int* const p) {}
void foo(int p[]) {}
-----------------------------------------------
test.cpp:3:6: error: redefinition of 'foo'
void foo(int p[]) {}
     ^
test.cpp:2:6: note: previous definition is here
void foo(int* const p) {}
     ^
1 error generated.
April 02, 2019
On Monday, 1 April 2019 at 20:51:44 UTC, Walter Bright wrote:
> On 4/1/2019 1:00 PM, Rubn wrote:
>> Arrays in C++ are just pointers.
>
> No, they're not.

Yes they are. The only time an array exists in C++ is (oddly) only when you pass it by reference :). Otherwise every operation you do on array, any time you pass an array to a function that isn't a reference it is just a pointer. This is why buffer overflows exist in C++, because an is literally just a pointer -- it doesn't even know it's own size! How can you call that an array?

>> If you can't have a pointer to something, it is only natural you can't have array either.
>
> g++ -c test.cpp
> test.cpp: In function void test():
> test.cpp:1:24: error: declaration of p as array of references
>  void test() {  int& p[3]; }
>                         ^
>
> As I said, C++ ref can only appear at the top of an AST, which is what a "storage class" is.
>
> C++ tries to have it be both a floor wax and a desert topping, making for a device that nobody understands.

So you are saying void is also a "storage class" ?

> Be careful what you wish for.

I'm not wishing for anything. You entered the discussion and stated that it isn't a type. And that's what I've been arguing against.

April 02, 2019
On Monday, 1 April 2019 at 23:04:15 UTC, Atila Neves wrote:
> On Monday, 1 April 2019 at 20:00:34 UTC, Rubn wrote:
>> On Monday, 1 April 2019 at 13:57:17 UTC, Atila Neves wrote:
>>> On Monday, 1 April 2019 at 13:09:28 UTC, Dein wrote:
>>>> On Monday, 1 April 2019 at 01:18:44 UTC, Walter Bright wrote:
>>>>> On 3/31/2019 5:35 PM, Rubn wrote:
>>>>>> you can literally use it everywhere else you can use a type.
>>>>>
>>>>> No, you can't. An array of refs won't compile, either.
>>>>>
>>>>>   void test(int& a[]); // error
>>>>>
>>>>> A C++ ref can only appear at the top of a type AST, which is unlike any other type. Which exactly matches the only place a storage class can be!
>>>>
>>>> Seriously? You should know as well as I do what that function actually translates to:
>>>>
>>>>    void test(int&* const a);
>>>>
>>>> So I ask you now, how do you get a pointer to a reference. Its the exact same thing. Not sure if you are trying to just deceive me with some syntax sugar in C++ or what.
>>>
>>> Bad example, but the point stands:
>>>
>>>
>>> ----
>>> // foo.cpp
>>> int fun() {
>>>     int& foo[5]; // doesn't compile
>>> }
>>> ----
>>>
>>> I'd never even thought of it until Walter mentioned it that one can't have an array of references. Huh.
>>
>> Arrays in C++ are just pointers. If you can't have a pointer to something, it is only natural you can't have array either.
>
> Arrays in C (and by extension C++) are most definitely not "just pointers". This is a common misconception due to arrays decaying to pointers in function calls. There are such things as array pointers in C, and C++ adds array references to the mix for, in all likelihood, consistency. I haven't met many C programmers that know of their existence.
>
>
>>     void* ptr;   // ok
>>     void arr[5]; // error
>>
>> So I guess Walter agrees that void isn't a type then right? You can't have an array to it so that's the deciding factor.
>
> Funnily enough your example here shows how pointers and arrays aren't the same thing. The reason you can't have an array of "voids" in C is because void has no size and the whole thing is nonsensical. It's a good point though that void is treated differently in C's type system.

I never said they are the same thing. An array can only (with a minor exception) be represented by a pointer, if a pointer can't exist then neither can the array.
April 01, 2019
On 4/1/19 7:43 PM, Rubn wrote:
> On Monday, 1 April 2019 at 20:37:03 UTC, Walter Bright wrote:
>> On 4/1/2019 6:09 AM, Dein wrote:
>>> Not sure if you are trying to just deceive me with some syntax sugar in C++ or what.
>>
>> You can try it yourself:
>>
>> ----------
>> g++ -c test.cpp
>> test.cpp:1:17: error: cannot declare pointer to int&
>>  void test(int&* p);
>>                  ^
>> ----------
>>  g++ -c test.cpp
>> test.cpp:1:18: error: declaration of p as array of references
>>  void test(int& p[]);
>>                   ^
>> ----------
> 
> You can try it yourself:
> 
> void foo(int* const p) {}
> void foo(int p[]) {}
> -----------------------------------------------
> test.cpp:3:6: error: redefinition of 'foo'
> void foo(int p[]) {}
>       ^
> test.cpp:2:6: note: previous definition is here
> void foo(int* const p) {}
>       ^
> 1 error generated.

The fact that we have somebody teaching Walter Bright the C language to is supremely ironic in wake of the recent discussions.