Zig: a great fit for emulators - Benjamin Feng

Поделиться
HTML-код
  • Опубликовано: 1 окт 2024

Комментарии • 17

  • @JobvanderZwan
    @JobvanderZwan 4 года назад +88

    "The expressiveness of assembly code coupled with the efficiency of JavaScript"
    Well I'm sold

  • @jfltech
    @jfltech 4 года назад +18

    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.

    • @death-disco
      @death-disco 4 года назад +9

      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.

    • @ishanagarwal475
      @ishanagarwal475 3 года назад +6

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

    • @secondaryaccount8155
      @secondaryaccount8155 2 года назад +3

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

  • @marijnstollenga1601
    @marijnstollenga1601 4 года назад +5

    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.

  • @NikolajLepka
    @NikolajLepka 3 года назад +6

    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"

    • @maksymiliank5135
      @maksymiliank5135 7 месяцев назад

      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.

  • @FrankHarwald
    @FrankHarwald Год назад +2

    11:40 still no way of writing a portable packed type in C! GCC uses __attribute((packed)) while Visual C & Clang uses #pragma pack()

  • @UliTroyo
    @UliTroyo 3 года назад +2

    Great talk, and interesting project! I'm definitely going to be following this one.

  • @jcamargo2005
    @jcamargo2005 Год назад +2

    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.

    • @jcamargo2005
      @jcamargo2005 Год назад

      Sure C compilers will add padding but the variables in this struct are perfectly aligned

    • @yjlom
      @yjlom Год назад +1

      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 */
      }

  • @salonsospain
    @salonsospain Месяц назад

    3453

  • @alexgorodecky1661
    @alexgorodecky1661 3 года назад +6

    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

    • @garchomp2222
      @garchomp2222 2 года назад +2

      "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

    • @maksymiliank5135
      @maksymiliank5135 7 месяцев назад

      Yes, I do believe zig is better for bit manipulation. Read the "Packed structs in Zig make bit/flag sets trivial" blog post.