|
You mean like a function that takes a length and int, like say something like thiscode:
|
# ? Mar 28, 2023 10:01 |
|
|
# ? May 27, 2024 05:57 |
|
His Divine Shadow posted:You mean like a function that takes a length and int, like say something like this It'd have to take the array, something like: code:
|
# ? Mar 28, 2023 10:13 |
|
Oh yeah, gotcha.
|
# ? Mar 28, 2023 10:42 |
|
A C++ behaviour that has stumped someone who wrote a time-travelling debugger: https://twitter.com/rocallahan/status/1643340192034742272 I can’t figure out how to copy from godbolt on my phone, so here’s a screenshot:
|
# ? Apr 5, 2023 00:24 |
|
I think any compiler should refuse to compile that, out of principle.
|
# ? Apr 5, 2023 01:48 |
|
Subjunctive posted:A C++ behaviour that has stumped someone who wrote a time-travelling debugger: This is an affront to God, is what it is.
|
# ? Apr 5, 2023 01:49 |
|
Presto posted:I think any compiler should refuse to compile that, out of principle. I am sure there is some very well-thought out reason that this doesn't throw an error at the X enumerator, but sometimes people who get too deep into details end up missing some perspective....
|
# ? Apr 5, 2023 01:56 |
|
I can't even tell if the question is "is it a compiler bug to compile this" or "is it a compiler bug to fail to compile this".
|
# ? Apr 5, 2023 02:12 |
|
Presto posted:I think any compiler should refuse to compile that, out of principle. Absurd Alhazred posted:This is an affront to God, is what it is. OK sure but I think we’ve established that C++ is outside the bounds of conventional spirituality and morality, so I’m looking for a more secular answer
|
# ? Apr 5, 2023 02:13 |
|
roomforthetuna posted:I can't even tell if the question is "is it a compiler bug to compile this" or "is it a compiler bug to fail to compile this". I’ll take either! I’m not picky.
|
# ? Apr 5, 2023 02:14 |
|
Subjunctive posted:I’ll take either! I’m not picky.
|
# ? Apr 5, 2023 02:18 |
|
Subjunctive posted:OK sure but I think we’ve established that C++ is outside the bounds of conventional spirituality and morality, so I’m looking for a more secular answer C++ is proof that I, personally, am in hell.
|
# ? Apr 5, 2023 02:20 |
|
rjmccall is going to have a couple of drams and pop in here and drop chapter-and-verse on us and this place is the best I have ever spent
|
# ? Apr 5, 2023 02:23 |
|
Ordinary names and tag names can coexist in the same scope. In C, they are completely independent namespaces, and you have to write a tag specifier to resolve a tag name, e.g. struct foo. C++ wanted to let you write class names without the extra keyword, so ordinary lookup can find tag names, but in an effort to preserve C compatibility, tag names are hidden by ordinary names in the same scope unless you’re doing tag lookup specifically. Naturally this rule in C++ also applies in a million situations that are impossible to write in C, like qualified lookup. Anyway, GCC is loving up the lookup performed for an elaborated type specifier, which needs to be a tag lookup and so ignore non-tag names. Probably they’re failing to preserve the fact that this is an elaborated type specifier when they record the dependent name within a template.
|
# ? Apr 5, 2023 02:28 |
|
Subjunctive posted:rjmccall is going to have a couple of drams and pop in here and drop chapter-and-verse on us and this place is the best I have ever spent Goddamnit …I’m not looking up the citations
|
# ? Apr 5, 2023 02:30 |
|
rjmccall posted:Words I've been programming C++ for over 20 years now, and I have no idea what you just said.
|
# ? Apr 5, 2023 02:38 |
|
Does that mean struct Foo::X should be resolving to the enum that has shadowed the struct? In this context is it even possible to specify struct Foo::struct X?
|
# ? Apr 5, 2023 02:52 |
|
roomforthetuna posted:Does that mean struct Foo::X should be resolving to the enum that has shadowed the struct? In this context is it even possible to specify struct Foo::struct X? No, AIUI `struct Foo:X` is an explicit tag name lookup which should ignore the enum.
|
# ? Apr 5, 2023 02:54 |
|
Is there a legit reason to do that, whatever it is?
|
# ? Apr 5, 2023 02:56 |
|
Subjunctive posted:No, AIUI `struct Foo:X` is an explicit tag name lookup which should ignore the enum.
|
# ? Apr 5, 2023 02:57 |
|
roomforthetuna posted:Not sure I get it. Foo::X would refer to the enum then, because it's not explicitly a tag, but then if you had something shadowing Foo, so you have to specify struct Foo, then it would become impossible to reference the enum? Parentheses I imagine? (struct Foo)::X vs default of struct (Foo::X)? I dunno, I’m just trying to be so egregiously wrong that rjmccall steps in again.
|
# ? Apr 5, 2023 03:00 |
|
Presto posted:I've been programming C++ for over 20 years now, and I have no idea what you just said. Have you ever seen old C code that does something like: "typedef struct X {} X;"? Well, that's because in C if you just do "struct X {};" you can't do "X var;" it has to be "struct X var;" which is kinda verbose.... And C++ did some weird thing where you can write "X var;" but it still cares about the distinction sometimes.
|
# ? Apr 5, 2023 03:36 |
|
roomforthetuna posted:Does that mean struct Foo::X should be resolving to the enum that has shadowed the struct? In this context is it even possible to specify struct Foo::struct X? struct Foo::X is an elaborated type specifier, in this case using this production: code:
code:
A microsecond earlier, the compiler was processing the struct Base::X in the template definition. It immediately did an unqualified nested-name-specifier lookup for Base and found the template type parameter. It then immediately tried to do a qualified tag lookup into that scope for X, but it could not because the scope specifier was dependent. So instead it wrote down that it had a dependent type name, including all the relevant details of the lookup like the identifier X and the dependent scope Base::. When the compiler instantiates the template definition for Base=Foo, it sees the record of the dependent type name and tries to instantiate it. First, it must try to resolve the dependent scope Base:: to something concrete, which it does by resolving the template parameter Base to the corresponding template argument Foo. It can now do a qualified lookup into that scope. It is supposed to do a qualified tag lookup, which should resolve exactly like it did in the non-dependent case. However, I'm assuming they forgot to write down that the elaborated type specifier was written with struct, so instead the compiler is resolving the name as if it were written with typename, which does not do a tag lookup and so resolves to the enumerator and dies because that's not a type. rjmccall fucked around with this message at 03:56 on Apr 5, 2023 |
# ? Apr 5, 2023 03:51 |
|
I wish to subscribe to the "rjmccall explains C++" service.
|
# ? Apr 5, 2023 08:57 |
|
C++ code looks so loving incomprehensible to me compared to regular C.
|
# ? Apr 5, 2023 12:50 |
|
Xarn posted:I wish to subscribe to the "rjmccall explains C++" service.
|
# ? Apr 5, 2023 13:13 |
|
His Divine Shadow posted:C++ code looks so loving incomprehensible to me compared to regular C. Depends how up their own rear end the author is about template metaprogramming. But yeah, C is a great language.
|
# ? Apr 5, 2023 15:21 |
|
Xarn posted:I wish to subscribe to the "rjmccall explains C++" service. roomforthetuna posted:Yeah, that was a really great explanation that semi-ordinary humans can understand. Thanks rjmccall!
|
# ? Apr 5, 2023 15:45 |
|
His Divine Shadow posted:C++ code looks so loving incomprehensible to me compared to regular C. Tbf that example is a pathological case and if you submitted a PR with that code in my workplace people would be asking what kind of drugs you were on.
|
# ? Apr 5, 2023 18:18 |
|
ultrafilter posted:Is there a legit reason to do that, whatever it is? Having a nested type and an enum case with the same name isn't a good idea, but since it works it seems like an unsurprising thing to have just incidentally happen given enough code written with a naming convention that makes it possible.
|
# ? Apr 5, 2023 21:36 |
|
The most annoying naming conflicts I generally run into are all in union-like situations where, yeah, it’s not uncommon to want to name a nested type, a union field, and an enumerator all the same thing: a nested type to abstractly represent what I want to store in some case, a union field to actually add the storage for that case, and an enumerator in an enum that I store separately to say which case I’m in. I have the misfortune of working in codebases with a legacy of capitalizing local variable and field names, though.
|
# ? Apr 5, 2023 22:30 |
|
His Divine Shadow posted:C++ code looks so loving incomprehensible to me compared to regular C. C++ is a nifty expansion of C if you just limit yourself to the right parts. It can also be a fairly clean modern language if you just stick to those parts. The problem is that nobody agrees on which parts are the good ones, and you can't entirely avoid the rest. I rarely reach for C++; if I want a low level language I'll stick to C, and if I want a modern language there are multiple alternatives that don't have more corner cases than a hedge maze. It's the best way to write Qt and fast R libraries, I guess? (Why am I in this thread if I'm so ambivalent to C++? Idk, I like C and hope to absorb some C++ by immersion?)
|
# ? Apr 7, 2023 04:23 |
|
No, no, ambivalence is about right.
|
# ? Apr 7, 2023 04:30 |
|
Computer viking posted:C++ is a nifty expansion of C if you just limit yourself to the right parts. It can also be a fairly clean modern language if you just stick to those parts. The problem is that nobody agrees on which parts are the good ones, and you can't entirely avoid the rest. Turn it into the C fanclub thread with me.
|
# ? Apr 7, 2023 04:32 |
|
C++ turned away from the face of god when it stepped beyond C With Classes. You could probably make a pretty decent language of it if you copied Swift's dynamic object layout thing and also made it more COM-like.
|
# ? Apr 7, 2023 04:48 |
|
ultrafilter posted:Is there a legit reason to do that, whatever it is? Adding a new rule just for the sake of making this be an error would be more complexity (+ technically break old code that did it, probably accidentally)
|
# ? Apr 7, 2023 04:52 |
|
C/C++ Thread: No right thinking people would do it on purpose
|
# ? Apr 7, 2023 04:53 |
|
Computer viking posted:C++ is a nifty expansion of C if you just limit yourself to the right parts. It can also be a fairly clean modern language if you just stick to those parts. The problem is that nobody agrees on which parts are the good ones, and you can't entirely avoid the rest. my problem with c++ is that I don't like c++ templates. i like generics the way they were done in later languages, but C++ templates are loving awful - they make compile times slow, they're slow to parse, and template metaprogramming is the most incomprehensible bs you'll ever see. unfortunately, you may have noticed that the stl is the "standard template library"... it's very difficult to enjoy programming in a language when you disagree with its foundation.
|
# ? Apr 7, 2023 06:05 |
|
Templates are awful, and I don't know anyone who really likes them. But then you use the modern replacement like Rust's traits and suddenly realize that you flat out cannot do things that would be simple in C++ (see e.g. variadic template packs).
|
# ? Apr 7, 2023 10:43 |
|
|
# ? May 27, 2024 05:57 |
|
Computer viking posted:C++ is a nifty expansion of C if you just limit yourself to the right parts. It can also be a fairly clean modern language if you just stick to those parts. The problem is that nobody agrees on which parts are the good ones, and you can't entirely avoid the rest. I use C++ a lot because you can mix and match it with C, and C has interoperability with tons of languages like Swift, Objective C, Kotlin, Golang, etc. This makes it still a top choice for anything that needs to be cross-platform on the long term. As you said though, you need to stick to the good parts. And you have to know all of them to make the right choices. I learned about std::execution::par just a few months ago for example. It's got a very rich standard library.
|
# ? Apr 7, 2023 12:08 |