Daniel Houck

11.6K posts

Daniel Houck

Daniel Houck

@daniel_houck

Katılım Şubat 2014
58 Takip Edilen59 Takipçiler
Jason Turner
Jason Turner@lefticus·
I just ran an experiment, and "fun fact"... Agentic AI did a more correct and more complete port of Doom to C++ than I was able to in 1/10 the time (1.5hrs), if you remember my epic live stream doing that...
English
16
5
174
60.6K
Daniel Houck
Daniel Houck@daniel_houck·
@shelvacu @n00bmind @lefticus I don’t know the C object model as well as the C++ one, but you are allowed to start using the pointer right away in C. In C++ you need to begin the lifetime of the Foo objects as a separate step, which now often happens implicitly but a few years ago always had to be explicit.
English
0
0
0
4
Jason Turner
Jason Turner@lefticus·
FYI for people who don't know the difference: C++ and C are not super/sub sets of each other. They have different: * reserved words * memory models * reserved words * notions of lifetime etc It's very easy to craft a C program that cannot compile in C++ mode.
Jonathan Blow@Jonathan_Blow

@lefticus What do you mean "port of Doom to C++"? It's in C...

English
45
11
479
88.9K
Daniel Houck
Daniel Houck@daniel_houck·
@JonathanLigmas @lefticus The cast is defined but unless it’s an implicit-lifetime type, *using* the pointer isn’t. I think during the original livestream there was no such thing as an implicit-lifetime type. And I’m not sure something with unions qualifies?
English
0
0
0
5
JohnBrown
JohnBrown@JonathanLigmas·
@daniel_houck @lefticus Foo must be a plain data struct in the C version right? Adding the cast in that case is safe/defined
English
1
0
0
17
Daniel Houck
Daniel Houck@daniel_houck·
@n00bmind @lefticus Or, the part about it still not being valid if you add the cast is the object model. The first part is the type system, but I was mostly using that as illustration to get to the object model part.
English
0
0
0
8
Daniel Houck
Daniel Houck@daniel_houck·
@n00bmind @lefticus You’re right, it’s the object model. I got confused because I consider them pretty closely related, but they are different.
English
2
0
0
40
Daniel Houck
Daniel Houck@daniel_houck·
@Zen_Feet @AlphaLegion101 @lefticus Very easy to *appear* to fix, with a cast, but that’s technically UB until recently unless you add a placement new instead. And the placement new for arrays doesn’t work right. There were other issues, but that’s the first one encountered and enough to show that 99% don’t work.
English
0
0
0
38
Daniel Houck
Daniel Houck@daniel_houck·
@Zen_Feet @Thomas_Hall888 @lefticus Until a few years ago using the result of the cast was UB in C++; it usually isn’t now (unless unions are involved I think?). That can usually be handled by a placement new after the malloc but that doesn’t work for arrays.
English
1
0
0
22
Daniel Houck
Daniel Houck@daniel_houck·
@noop_dev @lefticus Some could be solved with more casts, but apparently once everything compiled it still didn’t link because of something I haven’t yet looked into the details of involving function pointers and callbacks.
English
1
0
0
18
Daniel Houck
Daniel Houck@daniel_houck·
@noop_dev @lefticus I might be wrong about the timing; the first port might have been after that paper and implicit lifetimes. That still needs some porting because the Doom code used idiomatic C without those casts. There were other issues; I just use that example because it was the first.
English
1
0
0
18
Daniel Houck
Daniel Houck@daniel_houck·
@noop_dev @lefticus Yes, no initialization happens, but C++ still distinguishes between uninitialized memory with nothing in it and memory with an object where the bytes happen to be uninitialized. Yes, even an object of POD type.
English
0
0
0
17
Boris Chuprin
Boris Chuprin@noop_dev·
@daniel_houck @lefticus BTW, if you don't init anything in your constructor, all memory allocated to a class instance remains uninitialized, for members without own constructors (or with empty constructors also), yet this is legal C++. C++ is not mandating you to init memory with or without constructors
English
1
0
0
23
Daniel Houck
Daniel Houck@daniel_houck·
@noop_dev @lefticus This is less true now after open-std.org/jtc1/sc22/wg21…, but it is still true for some types. I think everything you can do with arrays and structs in code that’s valid C makes an implicit-lifetime type, but I’m not sure about unions.
English
0
0
0
7
Daniel Houck
Daniel Houck@daniel_houck·
@noop_dev @lefticus I didn’t mean a C-style cast was a bug or UB. I meant using the result of `malloc` as a pointer to Foo is UB. There is no `Foo` object there; there is just uninitialized memory and you need to separately create the object with placement new.
English
2
0
0
34
Daniel Houck
Daniel Houck@daniel_houck·
@noop_dev @lefticus You can ignore the C programmers I know and say the cast should be there anyway. Maybe I only know bad C programmers. It is still UB in C++, especially six years ago when he did the original port. Do you consider “even UB that seems to work is bad” to be part of the BS?
English
1
0
0
17
Daniel Houck
Daniel Houck@daniel_houck·
@noop_dev @lefticus Okay, narrowing down to a starting point. There is a type Foo and a positive int n. In C, if I wrote Foo *foos = (Foo*)malloc(n * sizeof(Foo)); I think every C programmers I know would say the cast is a bug or at least a smell. Without the cast, it does not compile in C++.
English
2
0
0
38
Daniel Houck
Daniel Houck@daniel_houck·
@harshad1313 @lefticus They definitely do not. They disagree on when objects start to exist and when they stop existing. In C++ a malloc is not always enough to create an object, and especially wasn’t six years ago during his port.
English
0
0
0
45
Harshad
Harshad@harshad1313·
@lefticus Memory model? They have the same memory model?
English
1
0
0
444