April 02
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.
>
>
>> 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.

Let's put it this way, is const a type? No? You would say it is a "sturage class". Considering the following now though:

What do you think the following code is going to print?

    import std.stdio;

    void foo(T)(T a) {
        writeln(T.stringof);
    }

    template is_same(T, G) {
        enum is_same = is(T == G);
    }

    void main() {
        int a;
        const int b;

        foo( a );
        foo( b );

        writeln( "is_same: ", is_same!(typeof(a), typeof(b)) );
    }

April 02
On Tuesday, 2 April 2019 at 00:13:13 UTC, Andrei Alexandrescu wrote:
> 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.

Guess he's spent too much time in the D he's become a bit rust-y..
April 02
On Tuesday, 2 April 2019 at 00:06:23 UTC, Rubn wrote:
> 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,


>> 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.

"Arrays in C++ are just pointers".

> An array can only (with a minor exception) be represented by a pointer, if a pointer can't exist then neither can the array.

Factually incorrect.


April 02
On Tuesday, 2 April 2019 at 00:00:34 UTC, Rubn wrote:
> 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?

Every word in this paragraph is wrong, including "the", "yes", and "it".
April 01
On 04/01/2019 05:00 PM, Rubn wrote:
> 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.

Sensational but wrong. For example, there is no pointer in the following C++ code yet there is an array:

#include <iostream>

using namespace std;

struct S {
  int arr[10];
};

int main() {
  cout << sizeof(S) << '\n';
}

I know that you can qualify your statement to make it correct in some contexts but you are not doing so (yet?).

Ali

April 02
On Tuesday, 2 April 2019 at 00:00:34 UTC, Rubn wrote:
> 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?

I love it, stridently arguing with Walter about the basics of C++, one of the few people in the world who groks the basics of the language well enough to implement a compiler for it*!

Obviously there's always a chance he's wrong about things, but on a topic like this? Very bad odds. :)

* Memorizing the standard & writing a million lines of C++ code would be no guarantee of getting to this level.
April 02
On 4/1/2019 5:20 PM, Rubn wrote:
> Let's put it this way, is const a type?

No. It's a "type qualifier".
April 02
On 4/1/2019 4:04 PM, Atila Neves wrote:
> It's a good point though that void is treated differently in C's type system.

Void is treated as a degenerate type, and as you say, rejected constructs like arrays of void are rejected because they are nonsense. Arrays of functions are similarly rejected.

Not at all like what goes on with ref in C++, because an array of refs could have perfectly reasonable semantics. But they are not allowed in C++, because ref is a storage class pretending to be a type.

April 02
On 4/1/2019 5:55 PM, Atila Neves wrote:
> Factually incorrect.

I suspect Rubn has confused the syntactical conflation of arrays with pointers in C, and the implicit coercion of arrays to pointers, as them being the same. They simply aren't the same, as they are semantically separated by one level of indirection.

I wrote an article about it calling this "C's Biggest Mistake", as this has led to decades of crashes and malware infestations:

https://www.digitalmars.com/articles/b44.html
April 02
On Tuesday, 2 April 2019 at 00:13:13 UTC, Andrei Alexandrescu wrote:
> On 4/1/19 7:43 PM, Rubn wrote:
>> On Monday, 1 April 2019 at 20:37:03 UTC, Walter Bright wrote:
>>> [...]
>> 
>> 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.

Here's an egg and this is how you suck it...
1 2 3 4 5 6 7