Benjamin is cool to talk to and answers questions live on twitch, I asked him why Zig over the current new'ish' compiled langs such as Rust, Go, Nim.. he replied, (paraphrasing) Go: Preferred no garbage collector but like the language, Nim: didn't know about it when he started, Rust: didn't like upfront complexity.
imo rusts upfront difficulty is a barrier that you only cross once. And if we judged everything by how difficult it was to learn rather than its actual output, we'd be in a sad situation with technology. Imagine if they applied that philosophy to hardware design.
@@death-disco I don't want to be disrespectful but the reason why C was made was to hide the complexity and variation of the hardware a developer had to encounter when deploying a software which is already hard enough.
@@ishanagarwal475 The funny thing about the rust indoctrinated fanboys is that they keep repeating the same non-sense over and over while never providing the formal proof to back their claims.
Great talk! Would be awesome to have a GGPO style system for emulators in Zig, where both users run their own emulators (for low local latency) and the results get synchronised by rolling back the emulators appropriately.
C does have byte offsets within structs, doesn't it? I seem to remember being taught this in my college C course. Suffixed with "don't ever use this though, because C doesn't have odd-sized integers, and so it would be a pain to use outside the struct"
I don't know what you mean by struct offsets. C inserts padding to structs if their fields are not aligned properly. You can force the compiler to create a packed struct but that option is compiler specific. You can also add some fields to create an offset, for example by inserting an "uint8_t unused1;" in the middle of your struct. There are also bitfields in C. For example: struct { char a : 4; char b : 4; } All of these things are not well defined by c standard and it's easy to introduce an undefined behavior.
Please somebody correct me, but using structs with unions is allowed in C. Only in C++ this runs into undefined behaviour. So the code example he showed in 14:54 would work in C.
using unions in structs is defined, but accessing a union field other than was last set is undefined union Foo { unsigned u; int i; } int main (void) { union Foo x = {.i = 15}; int y = x.i; /* that's ok */ unsigned z = x.u; /* the compiler can make of this absolutely whatever it wants */ x.u = 15u; y = x.i; /* now this is undefined */ z = x.u; /* and this works fine */ }
No sense criticism for C - The Byte Cruncher King. Really, Zig is better with Byte manipulation? Don't think so. I think Zig has a lot of advantages over C, but not in this area
"A lot better designs" in reference to it being a "modern language", 1) not a great qualifier to begin with 2) old does not imply worse 3) C is has strengths/weakness so does zig
"The expressiveness of assembly code coupled with the efficiency of JavaScript"
Well I'm sold
Benjamin is cool to talk to and answers questions live on twitch, I asked him why Zig over the current new'ish' compiled langs such as Rust, Go, Nim.. he replied, (paraphrasing) Go: Preferred no garbage collector but like the language, Nim: didn't know about it when he started, Rust: didn't like upfront complexity.
imo rusts upfront difficulty is a barrier that you only cross once. And if we judged everything by how difficult it was to learn rather than its actual output, we'd be in a sad situation with technology. Imagine if they applied that philosophy to hardware design.
@@death-disco I don't want to be disrespectful but the reason why C was made was to hide the complexity and variation of the hardware a developer had to encounter when deploying a software which is already hard enough.
@@ishanagarwal475 The funny thing about the rust indoctrinated fanboys is that they keep repeating the same non-sense over and over while never providing the formal proof to back their claims.
Great talk! Would be awesome to have a GGPO style system for emulators in Zig, where both users run their own emulators (for low local latency) and the results get synchronised by rolling back the emulators appropriately.
C does have byte offsets within structs, doesn't it?
I seem to remember being taught this in my college C course. Suffixed with "don't ever use this though, because C doesn't have odd-sized integers, and so it would be a pain to use outside the struct"
I don't know what you mean by struct offsets. C inserts padding to structs if their fields are not aligned properly. You can force the compiler to create a packed struct but that option is compiler specific. You can also add some fields to create an offset, for example by inserting an "uint8_t unused1;" in the middle of your struct. There are also bitfields in C. For example:
struct {
char a : 4;
char b : 4;
}
All of these things are not well defined by c standard and it's easy to introduce an undefined behavior.
11:40 still no way of writing a portable packed type in C! GCC uses __attribute((packed)) while Visual C & Clang uses #pragma pack()
Great talk, and interesting project! I'm definitely going to be following this one.
Please somebody correct me, but using structs with unions is allowed in C. Only in C++ this runs into undefined behaviour. So the code example he showed in 14:54 would work in C.
Sure C compilers will add padding but the variables in this struct are perfectly aligned
using unions in structs is defined, but accessing a union field other than was last set is undefined
union Foo
{
unsigned u;
int i;
}
int
main (void)
{
union Foo x = {.i = 15};
int y = x.i; /* that's ok */
unsigned z = x.u; /* the compiler can make of this absolutely whatever it wants */
x.u = 15u;
y = x.i; /* now this is undefined */
z = x.u; /* and this works fine */
}
3453
No sense criticism for C - The Byte Cruncher King. Really, Zig is better with Byte manipulation? Don't think so. I think Zig has a lot of advantages over C, but not in this area
"A lot better designs" in reference to it being a "modern language",
1) not a great qualifier to begin with
2) old does not imply worse
3) C is has strengths/weakness so does zig
Yes, I do believe zig is better for bit manipulation. Read the "Packed structs in Zig make bit/flag sets trivial" blog post.