You don't need Generics in C

Sdílet
Vložit
  • čas přidán 2. 06. 2024
  • Previous Episodes: • Music Visualizer
    References:
    - Tsoding - Musializer - github.com/tsoding/musializer
    - github.com/nothings/stb/blob/...
    - nu11 - CZcams - / @nu11_ft
    - nu11 - WIP Works 2016-2022 - / nu11-wip-works-2016-2022
    - pilotredsun - Achievement (full album) - • pilotredsun - Achievem...
    Support:
    - BTC: bc1qj820dmeazpeq5pjn89mlh9lhws7ghs9v34x9v9
    - Servers: zap-hosting.com/en/shop/donat...
    Chapters:
    - 0:00:00 - Announcement
    - 0:00:55 - Demo
    - 0:02:04 - Hotreloading
    - 0:06:26 - Asset Manager
    - 0:12:19 - struct Assets
    - 0:14:50 - struct Images
    - 0:17:31 - CS Students are Shaking and Crying
    - 0:20:17 - CS Education
    - 0:23:00 - images_find()
    - 0:23:59 - Generalization
    - 0:25:26 - Generics in C
    - 0:28:27 - Padding
    - 0:30:54 - assoc_find()
    - 0:36:27 - Rust and C++ are Faster than C
    - 0:37:12 - But C could be as fast as Rust and C++
    - 0:39:50 - It's not About the Speed
    - 0:40:45 - assoc.c
    - 0:48:48 - decoupling from nob
    - 0:50:14 - Godbolt
    - 0:52:03 - Debugger
    - 0:55:10 - Summary
    - 0:57:24 - stb_ds.h
    - 0:58:45 - We are just having fun
    - 0:59:24 - offsetof that accepts values
    - 1:00:27 - Macro Arguments
    - 1:01:41 - Computing Offset Manually
    - 1:03:03 - typeof
    - 1:03:20 - C23
    - 1:04:30 - AI Help
    - 1:04:53 - Final assoc_find()
    - 1:07:12 - Duck Typey Structures
    - 1:09:32 - Integrating assoc_find() back to plug.c
    - 1:11:26 - assets_image()
    - 1:15:02 - assets_texture()
    - 1:17:58 - assets_fonts()
    - 1:18:59 - Integrating the Assets Manager
    - 1:23:10 - Loading New Texture
    - 1:26:22 - assets_unload_everything()
    - 1:29:19 - Updating Already Loaded Texture
    - 1:32:35 - Hotreloading Icons
    - 1:33:43 - Summary
    - 1:34:44 - Limitations
    - 1:35:32 - Reloading Textures One More Time
    - 1:36:19 - C is all you need
    - 1:37:17 - Outro
  • Věda a technologie

Komentáře • 175

  • @malekith6522
    @malekith6522 Před 6 měsíci +57

    I'm not a computer science student but a former electrical engineering student. In university, our professors, as you mentioned, presented it as a faster algorithm, claiming it's better than linear, etc. They emphasized learning different approaches, like bubble sort, to understand various methods. However, only at work did I learn that bubble sort or linear algo is not entirely useless. It can be used for certain projects, especially in specific conditions and for small input sizes. This is due to its simpler implementation, making it suitable for non-critical roles. If a more efficient approach is needed in the future, we can always make that change. Nonetheless, using simpler algorithms in certain scenarios can result in faster development and better code readability. By the way, this argument always can trigger some CS full-stack engineers :D.

    • @monad_tcp
      @monad_tcp Před 6 měsíci +18

      Actually the simpler implementation of linear search is faster until at least 20 elements in most modern CPUs, because of the size of the cache line.
      You wouldn't believe it. (not from theory, but do any sort of testing, this is a science after all)
      Computer science teachers live in the 1990s , and they teach things like you're programming a pentium100.
      Alas, all modern implementation of associative arrays are actually linear search until they grow big enough.
      No one is going to create a freaking red-black tree to store less than a 100 elements , heap dispatching causes cache misses .
      An array with linear search is faster for 100 elements than any tree, it loses to binary search and hash tables, but it's still unbelievably fast for small number of elements, you can literally get away with murder if you murder less than 100 elements (considering they're smaller structs, like 4 words)
      I get heated by that.

    • @malekith6522
      @malekith6522 Před 6 měsíci +4

      @@monad_tcp It's strange to hate science 😅. But yeah, you're absolutely right, mate! By the way, there's a difference when you take an engineering approach that's tightly connected to practice rather than just applying theory like it's dogma. Sadly, I see this trend with some developers who are not flexible in their solutions. They only apply best practices..

    • @monad_tcp
      @monad_tcp Před 6 měsíci +5

      @@malekith6522 "It's strange to hate science"
      Say that to the theoretical programmers that don't actually do science. I love the science part, I also love the mathematics part. "but in theory" yeah, I know theory, it applies when you have 10.000 elements, when you have less than 1000 elements, hardware optimization and practical limits apply more.
      Software engineering is a field that has a feet on mathematical theory and the other on practical science.
      People that only do one or the other trip and fall.

    • @monad_tcp
      @monad_tcp Před 6 měsíci +4

      Engineering is a field where you learn theory then you go practice to learn where to apply it.
      Novice programmers and student out of the universities take all theory as gospel and apply it everywhere and make a lot of mess like little kids in a puddle of dirty
      water.
      I just laugh at programmers with 3 years in the field that think they're senior because HR gave them the "senior title", that doesn't means you know shit yet.
      First go program for 5000h then come back. That will take 5 years of full time programming, but you are just out of the uni, you programmed for less than 300h and earned the senior title after 1 year because they just gave those automatically if you don't just quit after 1 year.
      And I know you didn't do your programming assignments and just played games, don't lie.
      I went to the uni and I know how it is.

    • @malekith6522
      @malekith6522 Před 6 měsíci +1

      @@monad_tcp This also concludes my observation. Seriously, I wouldn't dare to label myself as a senior software engineer with only 3 years of experience; I'd consider myself more of a mid-level professional.
      I noticed this misalignment a lot during university, especially when studying DSP, Digital electronics or any other EE stuff. There was a noticeable difference between theoretical knowledge in the lab and the practical application when we attempted to filter real signals and obtain results and that how I started to think more like engenier.

  • @not_herobrine3752
    @not_herobrine3752 Před 6 měsíci +234

    gotta love turning c into ghetto c++ with macros

    • @c7rsed118
      @c7rsed118 Před 6 měsíci +15

      cool but kinda mess, i don't see a point why just not use c++ if you can

    • @elfamosokilluah3072
      @elfamosokilluah3072 Před 6 měsíci +1

      @@c7rsed118 Because C++ is not C with classes and generics

    • @cobbcoding
      @cobbcoding Před 6 měsíci

      @@c7rsed118c++ cool but kinda mess, i don't see a point why just not use javascript if you can

    • @guitarcat01
      @guitarcat01 Před 6 měsíci +51

      "ghetto c++" got me lmao

    • @awli8861
      @awli8861 Před 6 měsíci +4

      @@guitarcat01 same

  • @isaactfa
    @isaactfa Před 6 měsíci +50

    Another reason that generics can be more performant is that they don't require indirection. Doesn't apply here, because you're dealing with arrays anyways. But where in a language with generics you can have a type Element { t: T, }, in C it'd have to be Element { void *ptr_to_t; } that you need to dereference (which I'd be surprised if even the most aggressive compiler could optimize that away). The upshot is that you get automatic dynamic dispatch.

    • @CianMcsweeney
      @CianMcsweeney Před 5 měsíci +5

      The 'proper' way to get generic support in C is to implement some kind of "metaprogramming" in your codebase, it essentially just does what languages that natively support generics do. However, it adds a ton of complexity to a codebase so is only really recommended for larger projects where the benefits outweigh the overhead

    • @lmao4982
      @lmao4982 Před 5 měsíci

      It wouldn't be too out of the question for a compiler to do that if it is inlining the function no?

    • @charliesumorok6765
      @charliesumorok6765 Před 5 měsíci +1

      #define DEFINE_ELEMENT(T) struct Element__##T { T t; }
      #define ELEMENT(T) struct Element__##T

    • @deriamis
      @deriamis Před 4 měsíci +1

      C does generic function selection via the standard _Generic macro. It just doesn’t do source code generation without a lot more macro metaprogamming work.

  • @todsalomonssonsegerby9702
    @todsalomonssonsegerby9702 Před 6 měsíci +13

    I have to commend you for the educational way your are teaching. There is not a lot of people with the amount knowledge that you posses that could teach it in such a straight forward manner. For that I amend you. Great work.

  • @soniablanche5672
    @soniablanche5672 Před 6 měsíci +21

    linear lookup is actually faster than hash tables for low number of elements

  • @johanngambolputty5351
    @johanngambolputty5351 Před 6 měsíci +23

    There's a difference between "slow" and "not the fastest", and if its fast enough for a given purpose, "not the fastest" is just irrelevant, especially if there are other upsides (ex-python user here).
    Also void* clearly makes C a dynamic language ;)

    • @monad_tcp
      @monad_tcp Před 6 měsíci +1

      C only has 3 types : void, pointer and int
      Just like python. Python has Nil, PyObject and double

    • @CarlBach-ol9zb
      @CarlBach-ol9zb Před 5 měsíci

      >Also void* clearly makes C a dynamic language ;)
      No, but this statement certainly ensures you're retarded.
      It's like saying HTML is a programming language because it can be Turing Complete when used with CSS. HTML is not programming language simply because it was never made as a programming language.
      Likewise, just because you can do some dynamic language stuff in C with void* doesn't mean C is a dynamic language. Next what? C++ is a functional programming language because of lambdas? No. Its main focus isn't lambda calc. Stop spreading bullshit everywhere.

  • @dieSpinnt
    @dieSpinnt Před 4 měsíci +1

    Great stuff, thank you for the video Tsoder!:)
    I usually do this kind of stuff as a virtual filesystem. The gzipped(or else) resource pack file (no Zoomer here! hehe) is loaded, the archive file table is created. Later you can lazy-load/request a file/resource, that is also cached for subsequent requests. Additionally the physical filesystem (executable + something like "resource" folder structure, "images", "fonts", etc. you get it) is also mapped onto the virtual filesystem and has preference over the virtual filesystem. This is very convenient when developing, as you can edit and test new resources in-place under the folder tree structure without having to rebuild your resource archive. And to hit two birds with one stone, this may also be used later as a basis for a plugin system or additions and resources that the user may provide. Even patches or updates are deployable this way.
    Oh and because I am a coward, this lady here programs all the mentioned stuff in C++:P So I am very excited to see what you are brewing in your C-witchcraft-kitchen, hehehe:)

  • @mechaelbrun-kestler3868
    @mechaelbrun-kestler3868 Před 6 měsíci +14

    assoc_find demonstrates the reason that in C++ when storing mixed objects in one array you use pointers to the objects. By using pointers, sizeof(void*) == sizeof(anyobject*).

    • @monad_tcp
      @monad_tcp Před 6 měsíci +1

      But then you don't get 200 different specializations exploding your exe size

  • @sinasalahshour
    @sinasalahshour Před 6 měsíci +2

    30:12 you could explicitly set padding values to zero in memory allocation. then even if you include the padding in value comparison, it wouldn't matter because both item would have padding with value of 0.

  • @anon-fz2bo
    @anon-fz2bo Před 3 měsíci +2

    chad void* user vs avg malding generic/template rust user

  • @jaumeguimeramarquez2244
    @jaumeguimeramarquez2244 Před 6 měsíci

    Came here for yet another AoC 2023. Not disappointed.

  • @mage3690
    @mage3690 Před 6 měsíci +36

    CS student here: I trust my professor not at all (I trust no one generally -- personal experience is a much better teacher than "that nerd told me so," mostly because nerds are horrendous at communication), but he knows and teaches that arrays are faster than linked lists almost no matter what. Benefit of a small school, the webdev prof is the same guy as the DSA prof, and he happens to be a big fan of measuring real-world performance. So when he makes his DSA students implement a radix sort (in C++, no less!), you can bet that he'll make them implement it on both a linked list and a linear array and MEASURE the difference over a few million elements on their own machine. Doing that sort of thing disabuses starry-eyed students of the notion that linked lists are faster than arrays for almost any reason, and keeps him sane in webdev class. I've _never_ heard him make the first mention of performance in webdev -- and if I asked about it, he'd probably tell me that I'm in the wrong class to be asking about that sort of thing.

    • @user-ux2kk5vp7m
      @user-ux2kk5vp7m Před 6 měsíci +16

      In university we were always taught about how linked lists are often superior to dynamic arrays because ‘Big-O bro’. We ended up testing the two and found that in almost every single realistic benchmark (including prepending items to the front!), dynamic arrays won out. lol

    • @soniablanche5672
      @soniablanche5672 Před 6 měsíci +12

      linked list have a very niche use case. If for some reason you need to do a lot of insertion in the middle of the list and doing it sequentially or on elements that you have references to (remember, insertion in the middle of a list in a linked list is actually O(n) because you need to do a lookup first before inserting)

    • @user-ux2kk5vp7m
      @user-ux2kk5vp7m Před 5 měsíci

      @@soniablanche5672 Insertion in the middle isn’t even better with a linked list than a dynamic array in most realistic situations though. We benchmarked this at my university and the dynamic array *still* beat the linked list in all cases unless the input sizes were massive

    • @julians.2597
      @julians.2597 Před měsícem

      ​@@soniablanche5672 linked lists are a great data structure to combine with others, e.g. a linked list of arrays for very large arrays so that changing elements in the middle is much cheaper, but you still get most of the memory locality benefits by filling up entire cache lines between the indirections.

  • @wiktorwektor123
    @wiktorwektor123 Před 4 měsíci +3

    There is theshold when hash maps/dictionaries become faster than linear arrays, but your data set must be thousands of items or maybe even slightly more. If your data set has maybe 100 items linear arrays will always be faster, because they benefit from CPU cache locality.
    Better yet, implement this yourself and mesure which method is faster for your particular case. Language doesn't matter.

  • @debemdeboas
    @debemdeboas Před 6 měsíci

    i used to do this a lot when writing buffer encoders/decoders in Turbo Pascal

  • @Vethane
    @Vethane Před 6 měsíci +5

    what about _Generic introduced in C11?

  • @rogo7330
    @rogo7330 Před 6 měsíci +3

    offsetof + sizeof macros are to the rescue when you do search in memory and do not know how struct is padded or something

    • @monad_tcp
      @monad_tcp Před 6 měsíci +2

      C has reflection confirmed, where is your C++ now ?
      I'm kidding

  • @Stroopwafe1
    @Stroopwafe1 Před 6 měsíci +9

    (Unrelated to the video) Are you going to be doing Advent of Code this year Tsoding?

    • @JeersNX
      @JeersNX Před 6 měsíci

      i aint, bro it is too hard

    • @Roman-sn3kh
      @Roman-sn3kh Před 6 měsíci +3

      iirc he said on one stream like 3 weeks ago that is probably not gonna do it.

    • @samuraijosh1595
      @samuraijosh1595 Před 6 měsíci

      What is advent of code

    • @ardnys35
      @ardnys35 Před 6 měsíci

      ​@@samuraijosh1595one programming challenge every day for the entirety of December. just google advent of code and check out its website

    • @Stroopwafe1
      @Stroopwafe1 Před 6 měsíci

      @@samuraijosh1595 Advent of Code is a yearly event where every day from December 1st to December 25th you can do a programming challenge

  • @JohnDoe-np7do
    @JohnDoe-np7do Před 6 měsíci

    Lol that thumbnail matches perfectly with the title

  • @luismex5575
    @luismex5575 Před 6 měsíci +1

    Would You make a video to show us how to use emacs like You do, You are great !! And your content is amazing thanks

  • @ar_xiv
    @ar_xiv Před 5 měsíci +1

    I haven't made the leap yet from C# to C but the similarity of Raylib to Monogame really helps me feel like I can

    • @dantheman52420
      @dantheman52420 Před 5 měsíci +1

      I started really getting into C two years ago after 6 years of C#. It's super worth it to learn C because of the fundamentals. When you go back to C# you will really start to question what it's doing under the hood. Questions like that will make you write way more efficient code.

    • @mattmurphy7030
      @mattmurphy7030 Před 3 měsíci +1

      C is sincerely a very simple and easy language. The C book is like 100 pages.

  • @tcholly
    @tcholly Před 2 měsíci

    Amazing, just a thing:
    1:15:22 you do have LoadTexture in raylib

  • @arthurgrillo3462
    @arthurgrillo3462 Před 6 měsíci +1

    Tsoding, what about intrusive hashtables?

  • @ronaldomorillo3789
    @ronaldomorillo3789 Před 6 měsíci +16

    I implement generics by using 'hacky' macros for types which gives me type safety in C. Using void* is my last resort.

    • @vytah
      @vytah Před 6 měsíci +8

      This reminds me of "those aren't angle brackets, they're characters from the Canadian Aboriginal Syllabics block"

    • @VojtaJavora
      @VojtaJavora Před 6 měsíci +14

      ​​@@vytahsure, I can do generics
      **runs sed**

    • @user-ux2kk5vp7m
      @user-ux2kk5vp7m Před 6 měsíci

      Same. I have some single-header libraries I made for myself that implement macros to generate type-safe data structures like vectors, sets, hashmaps, etc. Really handy

    • @Isaac-zy5do
      @Isaac-zy5do Před 6 měsíci

      c11 has generic keyword, which makes some parts slightly better

    • @VictorRodriguez-zp2do
      @VictorRodriguez-zp2do Před 4 měsíci

      I have done the same using the mlib approach. It just ain't worth it though, to much hassle not to mention compiler error and static analyzers will give you harder to debug info

  • @l_t_m_f
    @l_t_m_f Před 6 měsíci

    in the end, isn't a hashtable just like using a enum who's integer corresponding values you can use as index keys in a linear array? asking for a friend

    • @anguruso
      @anguruso Před 5 měsíci +2

      Yes kind of, but it also handles the case where two keys hash to the same index.

  • @cheebadigga4092
    @cheebadigga4092 Před 6 měsíci +1

    always love the webdev bashing xD

  • @rifkysatyana2415
    @rifkysatyana2415 Před 3 měsíci

    What editor are u using ? Is this VIM or Emacs?

  • @ZoraAlven
    @ZoraAlven Před 6 měsíci +4

    Imagine compile C sources with -std=C23....

  • @supergem4845
    @supergem4845 Před 6 měsíci +1

    How can you do hot reloading in java I thought about using the dynamicClassLoader but the GC doesn't seem to happen correctly sometimes.

  • @loogabarooga2812
    @loogabarooga2812 Před 5 měsíci

    V interesting.
    Question, since i dont know much C: does endianness matter when trying to hop over the key string to get to the value? Or is that abstracted behind pointer arithmetic?
    Basically is it guaranteed that the first 8 bytes will be the key?

    • @charliesumorok6765
      @charliesumorok6765 Před 5 měsíci +1

      The first 8 bytes will always be the key since it is the first field and 8 bytes. Endianness might affect the order of those 8 bytes.

    • @mattmurphy7030
      @mattmurphy7030 Před 3 měsíci

      Endianness affects the order of bytes in a field, not the order of fields in a struct

  • @zlatin2830
    @zlatin2830 Před 2 měsíci

    what compiler are you using

  • @yummysoup
    @yummysoup Před 6 měsíci +5

    I was just wondering why you don't upgrade your computer. Why do you still use the old laptop.
    Curious to know.

    • @necuz
      @necuz Před 6 měsíci +23

      Using a slow computer keeps you based.

    • @johanngambolputty5351
      @johanngambolputty5351 Před 6 měsíci +5

      You might equally ask why upgrade, answer probably is "if it aint broke..."

    • @MisterConscio
      @MisterConscio Před 6 měsíci +1

      He's poor

    • @JamesSjaalman
      @JamesSjaalman Před 6 měsíci

      You appear to be a consumer. Do you have any *real* objections to his style or semantics?

  • @BobChess
    @BobChess Před 28 dny

    "You don't generic in C"
    Me when create data structures: make sense

  • @ingmarfalk3306
    @ingmarfalk3306 Před 6 měsíci +2

    Should you do aoc in porth ? Would be fun to see :D

  • @QckSGaming
    @QckSGaming Před 6 měsíci +2

    !!! Enterprise warning !!!

  • @hadeseye2297
    @hadeseye2297 Před 5 měsíci

    19:15 I just burst out laughing. Psychological therapy for High Languages Programmers. "It is fine. It is fine." And I also see an astronaut in a 50's hard sci-fim novel flying through space with earphones: "It is fine. It is fine."

  • @monad_tcp
    @monad_tcp Před 6 měsíci

    1:08:32 it's inheritance, you invented C++, now you just add a pointer to methods and you have a VTable.
    One can even say it's "structurally typed" to make TS people mad.

  • @monad_tcp
    @monad_tcp Před 6 měsíci +1

    29:43 it's gonna be fine.
    You don't need to support processors that need padding between a single 8 byte pointer and don't align on 4 byte boundary.
    No one uses any IBM mainframe here.

    • @mattmurphy7030
      @mattmurphy7030 Před 3 měsíci

      Same when people complain about endianness in serialization… name me one big endian machine

    • @julians.2597
      @julians.2597 Před měsícem

      @@mattmurphy7030 network

  • @norabelrose198
    @norabelrose198 Před 3 měsíci

    I literally laughed out loud at the title + thumbnail combo
    sure you can make it work in C with void* but it will be less performant bc of indirection and you have no compiler type safety to prevent you from shooting yourself in the foot

    • @U20E0
      @U20E0 Před 2 měsíci +1

      I don't think it's less performant because you can't pass a generic by value ( even if the language syntax says otherwise )
      You have to copy a chunk of data, which requires indirection anyway, so you actually gained nothing.
      This doesn't apply only to generics but to all structures ( that don't fit inside a register ).
      You can also just use a tagged union with an enum, that way you don't lose whatever type safety that C does offer ( and if you use -Wall it will even warn you about not handling all possible enum values in a switch statement )

    • @julians.2597
      @julians.2597 Před měsícem

      @@U20E0 you can pass generics by value in compiled languages because the compiler can generate the specific implementations without indirection at compile time for every time they were invoked with different types.

    • @U20E0
      @U20E0 Před měsícem

      @@julians.2597 As i said, generocs don't even matter. Passing a structure by value and passing a copy of it on the stack by reference literally compiles to the exact same instructions. Instructions which closer resemble the latter

  • @Purkinje90
    @Purkinje90 Před 6 měsíci +2

    When Jai comes out publicly, do you think you'll fully switch to Jai or continue to work in C?

    • @mattmurphy7030
      @mattmurphy7030 Před 3 měsíci +1

      “When” jai comes out 😂😂😂

    • @Purkinje90
      @Purkinje90 Před 3 měsíci

      @@mattmurphy7030 I have faith!

  • @yooyo3d
    @yooyo3d Před 6 měsíci

    When you are in doubt, use void*.

  • @con_sci
    @con_sci Před 6 měsíci +3

    UX designers on suicide watch

  • @overloader7900
    @overloader7900 Před 6 měsíci +3

    Have you worked with large pages yet? Most programs don't know they exist, but most modern CPUs have a separate TLB for large pages, so its practically exclusive for any app using them(though java can use them). This mem accesses to them a bit faster. Also pretty sure you'd need a separate pagefile for them, otherwise they are basically locked to memory, which can be useful.

    • @monad_tcp
      @monad_tcp Před 6 měsíci +1

      The 6 level associative TLB is a marvel to behold. It's hashtables all the way down.

  • @_supervolcano
    @_supervolcano Před 5 měsíci +1

    const char *key = *(const char**)((char*)items + i*item_size);

  • @nosojdjos
    @nosojdjos Před 5 měsíci

    Excuse my galactic ignorance, but what's the code editor you're using?

  • @dieSpinnt
    @dieSpinnt Před 4 měsíci

    You meant ( 50:12 ) the Matt Godot Game Engine?
    I only know Gal Gadot from the Wonder Woman Compiler Explorer!
    Hehehe, maximale Verwirrung *g*

  • @umutdogrru
    @umutdogrru Před 5 měsíci

    the editor you are using looks really nice, what is its name

    • @ruslansmirnov9006
      @ruslansmirnov9006 Před 5 měsíci +2

      Emacs

    • @wlcrutch
      @wlcrutch Před 5 měsíci

      @@ruslansmirnov9006 Vim is better

    • @ukyoize
      @ukyoize Před 5 měsíci +3

      it's called pico. I reccomend "boku no pico" fork.

  • @iDoComputers
    @iDoComputers Před 6 měsíci

    50:40 as a native german speaker, i could resist myself from laughing lol

  • @savantshuia
    @savantshuia Před 6 měsíci

    17:31 I'm sorry man, T_T

  • @mldy1
    @mldy1 Před 6 měsíci +3

    You should use the _Generic keyword instead of the macro for each function

  • @thomasgrady3103
    @thomasgrady3103 Před 5 měsíci +1

    c++ turning complete generics are bad obviously, but I really don't understand the issue with first-order generics? Just nicer syntax for a macro e.g.
    #define VECTOR_DECL(T) \
    struct Vector_##T { \
    ... \
    };
    vs if C had first-order generics
    struct Vector {
    ....
    };
    much nicer syntax. It's C so you could still have the compiler generate uninitialised memory instead of using RAII or whatever. And still just write
    Vector vector_new(int capacity) {
    Vector v;
    v.data = malloc(capacity * sizeof(T));
    return v;
    }
    This is pretty much how I program C++ anyway, and I don't understand why it's an issue. void* indirection is not simpler imo.

    • @ukyoize
      @ukyoize Před 5 měsíci

      Even simple generics in c++ cause it's name that is used by linker to get "mangeled", which means further incompatabilities between compilers and harder asembly interconnect.

    • @thomasgrady3103
      @thomasgrady3103 Před 5 měsíci +1

      @@ukyoize I get your point, but this is a design choice of the language and a fundamental limitation of linked libraries. Generics and dylibs are not compatible. Maybe a compiler that could monomorphize for binaries and transpile to void* for libs would be cool?

    • @deriamis
      @deriamis Před 4 měsíci +2

      C++ didn’t actually need name mangling to do name overloading. It *could* have instead just generated new function names and then used something like the way _Generic works in C11 and maintained complete binary compatibility with C.
      Name mangling was simply a poor design choice that would be hard to undo now. It’s not a good reason for not having first-order generics.

  • @snof7602
    @snof7602 Před 6 měsíci

    can you share discord server here please

    • @cobbcoding
      @cobbcoding Před 6 měsíci

      discord link is on the twitch channel

  • @phitc4242
    @phitc4242 Před 6 měsíci

    I do

  • @davydorynbaev
    @davydorynbaev Před 6 měsíci

    hello hello zozzing session

  • @fluentpwn8065
    @fluentpwn8065 Před 6 měsíci

    holy shit gf2 is cool

  • @sofiaknyazeva
    @sofiaknyazeva Před 6 měsíci +1

    Bro I need oxygen mask to breathe

  • @Techgeek002
    @Techgeek002 Před 6 měsíci

    Will you ever make a course for newbeginners

  • @gorenbk
    @gorenbk Před 6 měsíci +1

    i eat q-tips

  • @glowiak3430
    @glowiak3430 Před 6 měsíci +3

    void* goes brrrr

  • @Narblo
    @Narblo Před 6 měsíci

    What is the point to have a stable build of rust if they force you to use nightly?

  • @jack-zc3gj
    @jack-zc3gj Před 6 měsíci

    how exactly is c hot reloadable? cant find anything about this online and it does not seem to work in my testing

    • @dirrelito
      @dirrelito Před 6 měsíci

      Check older streams

    • @charliesumorok6765
      @charliesumorok6765 Před 5 měsíci

      C is not inherently hot-reloadable, but most OSes allow you to dynamically load code using shared libraries. They are *.so on Linux.

    • @mattmurphy7030
      @mattmurphy7030 Před 3 měsíci

      And I don’t believe that you can’t find anything because when I search C hot reloading I immediately come to CZcams videos about it and a library that implements it

  • @RealCatDev
    @RealCatDev Před 6 měsíci

    Hello!

  • @darknais
    @darknais Před 6 měsíci +6

    where is the CLITERAL located?

  • @PragandSens
    @PragandSens Před 6 měsíci

    Lol no generics

  • @yaksher
    @yaksher Před 6 měsíci +3

    If you're going to bother with the performance, wouldn't it make sense to
    - cut the common prefix of the path out of the keys (like ./resources/ is being compared for everything and you don't necessarily need support for resources outside of ./resources/, so they keys can omit it and then you can prepend ./resources/ to the keys if you need to load it)
    - maybe use a trie instead of a hash table, since a trie only requires you to read the string as far as until it's distinct from all other strings in the catalog (rather than the whole thing for hashing). You lose out a bit of performance in terms of it being less cache friendly than just reading the string, since you need to chase a pointer for each character read, but it seems likely to be faster, or at least worth trying. Definitely much less of a pain than setting up perfect hashing.

  • @ukyoize
    @ukyoize Před 5 měsíci +1

    I mean, real generics require name mangling

  • @michunel7022
    @michunel7022 Před 4 měsíci

    What about AI generation of code for each type you need? From some template in the comments or existing implementation for some specific type. Can it become the best way of doing generics in C?

  • @fattoofittoo7907
    @fattoofittoo7907 Před 6 měsíci

    how to become good problem solver in programming?

    • @mattmurphy7030
      @mattmurphy7030 Před 3 měsíci +1

      Practice. Solve 100 Leetcode problems and then you’ll know the answer to your question

  • @AnimeGIFfy
    @AnimeGIFfy Před měsícem

    so much echo

  • @bugrahanozcan8682
    @bugrahanozcan8682 Před měsícem

    Porn folder 6 GiB too small????

  • @OlliS71
    @OlliS71 Před 3 měsíci

    C is too much work compared to C++.

  • @eliseulucenabarros3920
    @eliseulucenabarros3920 Před 5 měsíci +1

    C IS EVERYTHING

  • @esepecesito
    @esepecesito Před 6 měsíci

    Data has types, not variables!

  • @user-hk3ej4hk7m
    @user-hk3ej4hk7m Před 5 dny

    The amount of cope from stdlib reinventers in the comments is off the charts.

  • @Eek_The_Cat
    @Eek_The_Cat Před 5 měsíci

    void* is a crime.

  • @leschopinesns100
    @leschopinesns100 Před 6 měsíci +2

    CS student for 5 years, spent 1000€ for my entire scholarship *laughs in french*

  • @HideoV
    @HideoV Před 5 měsíci

    why are you so triggered

  • @ChaotikmindSrc
    @ChaotikmindSrc Před 6 měsíci +5

    I'm a C lover don't get it wrong
    but generics/templates are a gift from god
    the complexity added by OOP/C++ is nearly satanic tho ;)

    • @IBelieveInCode
      @IBelieveInCode Před 6 měsíci +5

      "but generics/templates are a gift from god"
      It's just crap.

    • @ChaotikmindSrc
      @ChaotikmindSrc Před 5 měsíci

      @@IBelieveInCode if seriously think it is a good idea, maybe we didn't find the right way do it now

  • @iampointless
    @iampointless Před 6 měsíci +1

    Что это

    • @wetfloo
      @wetfloo Před 6 měsíci +1

      a void pointer

    • @RSchenal
      @RSchenal Před 6 měsíci +1

      музыкальный визуалайзер - музиалайзер

    • @samuraijosh1595
      @samuraijosh1595 Před 6 měsíci +2

      This content is not for Greeks.

    • @iampointless
      @iampointless Před 6 měsíci +1

      @@samuraijosh1595 i am not greek

  • @suprecam9880
    @suprecam9880 Před 4 měsíci +1

    I don't think your videos are bad, I just wish you would trim them down to a more appropriate length. You lose most people watching after a minute or two at most. Personally, I watched until 15:00 and found that I was still wondering when you were going to get to the point. Best of luck on your channel.