You don't need Generics in C

  Рет қаралды 62,486

Tsoding Daily

Tsoding Daily

Күн бұрын

Пікірлер: 186
@not_herobrine3752
@not_herobrine3752 10 ай бұрын
gotta love turning c into ghetto c++ with macros
@fghdfghdfgghdstwesdfjtykjyfgk
@fghdfghdfgghdstwesdfjtykjyfgk 10 ай бұрын
cool but kinda mess, i don't see a point why just not use c++ if you can
@elfamosokilluah3072
@elfamosokilluah3072 10 ай бұрын
@@fghdfghdfgghdstwesdfjtykjyfgk Because C++ is not C with classes and generics
@cobbcoding
@cobbcoding 10 ай бұрын
@@fghdfghdfgghdstwesdfjtykjyfgkc++ cool but kinda mess, i don't see a point why just not use javascript if you can
@guitarcat01
@guitarcat01 10 ай бұрын
"ghetto c++" got me lmao
@awli8861
@awli8861 10 ай бұрын
@@guitarcat01 same
@johanngambolputty5351
@johanngambolputty5351 10 ай бұрын
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 10 ай бұрын
C only has 3 types : void, pointer and int Just like python. Python has Nil, PyObject and double
@CarlBach-ol9zb
@CarlBach-ol9zb 9 ай бұрын
>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.
@grenadier4702
@grenadier4702 3 ай бұрын
@@monad_tcp is that irony?
@mechaelbrun-kestler3868
@mechaelbrun-kestler3868 10 ай бұрын
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 10 ай бұрын
But then you don't get 200 different specializations exploding your exe size
@malekith6522
@malekith6522 10 ай бұрын
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 10 ай бұрын
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 10 ай бұрын
@@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 10 ай бұрын
@@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 10 ай бұрын
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 10 ай бұрын
@@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.
@isaactfa
@isaactfa 10 ай бұрын
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 9 ай бұрын
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 9 ай бұрын
It wouldn't be too out of the question for a compiler to do that if it is inlining the function no?
@charliesumorok6765
@charliesumorok6765 9 ай бұрын
#define DEFINE_ELEMENT(T) struct Element__##T { T t; } #define ELEMENT(T) struct Element__##T
@deriamis
@deriamis 8 ай бұрын
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.
@anon-fz2bo
@anon-fz2bo 8 ай бұрын
chad void* user vs avg malding generic/template rust user
@soniablanche5672
@soniablanche5672 10 ай бұрын
linear lookup is actually faster than hash tables for low number of elements
@mattmurphy7030
@mattmurphy7030 7 ай бұрын
Cache locality ftw
@todsalomonssonsegerby9702
@todsalomonssonsegerby9702 10 ай бұрын
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.
@sinasalahshour
@sinasalahshour 10 ай бұрын
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.
@mage3690
@mage3690 10 ай бұрын
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 10 ай бұрын
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 10 ай бұрын
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 9 ай бұрын
@@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 5 ай бұрын
​@@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.
@ronaldomorillo3789
@ronaldomorillo3789 10 ай бұрын
I implement generics by using 'hacky' macros for types which gives me type safety in C. Using void* is my last resort.
@vytah
@vytah 10 ай бұрын
This reminds me of "those aren't angle brackets, they're characters from the Canadian Aboriginal Syllabics block"
@VojtaJavora
@VojtaJavora 10 ай бұрын
​​@@vytahsure, I can do generics **runs sed**
@user-ux2kk5vp7m
@user-ux2kk5vp7m 10 ай бұрын
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 10 ай бұрын
c11 has generic keyword, which makes some parts slightly better
@VictorRodriguez-zp2do
@VictorRodriguez-zp2do 8 ай бұрын
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
@wiktorwektor123
@wiktorwektor123 8 ай бұрын
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.
@Vethane
@Vethane 10 ай бұрын
what about _Generic introduced in C11?
@DelgardAlven
@DelgardAlven 10 ай бұрын
Imagine compile C sources with -std=C23....
@Stroopwafe1
@Stroopwafe1 10 ай бұрын
(Unrelated to the video) Are you going to be doing Advent of Code this year Tsoding?
@JeersNX
@JeersNX 10 ай бұрын
i aint, bro it is too hard
@Roman-sn3kh
@Roman-sn3kh 10 ай бұрын
iirc he said on one stream like 3 weeks ago that is probably not gonna do it.
@samuraijosh1595
@samuraijosh1595 10 ай бұрын
What is advent of code
@ardnys35
@ardnys35 10 ай бұрын
​@@samuraijosh1595one programming challenge every day for the entirety of December. just google advent of code and check out its website
@Stroopwafe1
@Stroopwafe1 10 ай бұрын
@@samuraijosh1595 Advent of Code is a yearly event where every day from December 1st to December 25th you can do a programming challenge
@con_sci
@con_sci 10 ай бұрын
UX designers on suicide watch
@dieSpinnt
@dieSpinnt 8 ай бұрын
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:)
@rogo7330
@rogo7330 10 ай бұрын
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 10 ай бұрын
C has reflection confirmed, where is your C++ now ? I'm kidding
@_supervolcano
@_supervolcano 9 ай бұрын
const char *key = *(const char**)((char*)items + i*item_size);
@Purkinje90
@Purkinje90 10 ай бұрын
When Jai comes out publicly, do you think you'll fully switch to Jai or continue to work in C?
@mattmurphy7030
@mattmurphy7030 7 ай бұрын
“When” jai comes out 😂😂😂
@Purkinje90
@Purkinje90 7 ай бұрын
@@mattmurphy7030 I have faith!
@yummysoup
@yummysoup 10 ай бұрын
I was just wondering why you don't upgrade your computer. Why do you still use the old laptop. Curious to know.
@necuz
@necuz 10 ай бұрын
Using a slow computer keeps you based.
@johanngambolputty5351
@johanngambolputty5351 10 ай бұрын
You might equally ask why upgrade, answer probably is "if it aint broke..."
@MisterConscio
@MisterConscio 10 ай бұрын
He's poor
@JamesSjaalman
@JamesSjaalman 10 ай бұрын
You appear to be a consumer. Do you have any *real* objections to his style or semantics?
@iDoComputers
@iDoComputers 10 ай бұрын
50:40 as a native german speaker, i could resist myself from laughing lol
@grenadier4702
@grenadier4702 3 ай бұрын
Isn't padding needed so that you improve performance excluding unnecessary cpu work?
@halfsourlizard9319
@halfsourlizard9319 3 ай бұрын
This would all be a lot easier / less hacky if you just ... removed the type system entirely.
@cheebadigga4092
@cheebadigga4092 10 ай бұрын
always love the webdev bashing xD
@luismex5575
@luismex5575 10 ай бұрын
Would You make a video to show us how to use emacs like You do, You are great !! And your content is amazing thanks
@user-hk3ej4hk7m
@user-hk3ej4hk7m 4 ай бұрын
The amount of cope from stdlib reinventers in the comments is off the charts.
@dieSpinnt
@dieSpinnt 8 ай бұрын
You meant ( 50:12 ) the Matt Godot Game Engine? I only know Gal Gadot from the Wonder Woman Compiler Explorer! Hehehe, maximale Verwirrung *g*
@monad_tcp
@monad_tcp 10 ай бұрын
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 7 ай бұрын
Same when people complain about endianness in serialization… name me one big endian machine
@julians.2597
@julians.2597 5 ай бұрын
@@mattmurphy7030 network
@QckSGaming
@QckSGaming 10 ай бұрын
!!! Enterprise warning !!!
@thomasgrady3103
@thomasgrady3103 9 ай бұрын
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 9 ай бұрын
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 9 ай бұрын
@@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 8 ай бұрын
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.
@grenadier4702
@grenadier4702 3 ай бұрын
Why do you use "void" for functions that don't accept any params? There's a compiler flag for that
@mariosshadow8533
@mariosshadow8533 2 ай бұрын
Because if you don't put void inside the parenthesis, the function doesn't have a prototype. And you can call it with any arguments. Because of course you can. I guess they didn't have '...' back then. As a consequence, you can't have func_name(...) nor func_name(void, ...) until C23. Bummer :(. Not that you should use it. To make a function prototype, you have to put something inside the parenthesis. C23 fixes this. Example: ```c #include int id() { return 1; } int main(void) { printf("%d ", id(1)); } ``` Compiling with `-std=c17`, no errors nor warning are output. Compiling with `-std=c23`, a hard error is given.
@arthurgrillo3462
@arthurgrillo3462 10 ай бұрын
Tsoding, what about intrusive hashtables?
@hadeseye2297
@hadeseye2297 9 ай бұрын
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."
@tcholly
@tcholly 7 ай бұрын
Amazing, just a thing: 1:15:22 you do have LoadTexture in raylib
@sofiaknyazeva
@sofiaknyazeva 10 ай бұрын
Bro I need oxygen mask to breathe
@BobChess
@BobChess 5 ай бұрын
"You don't generic in C" Me when create data structures: make sense
@ar_xiv
@ar_xiv 9 ай бұрын
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 9 ай бұрын
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 7 ай бұрын
C is sincerely a very simple and easy language. The C book is like 100 pages.
@monad_tcp
@monad_tcp 10 ай бұрын
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.
@bugrahanozcan8682
@bugrahanozcan8682 5 ай бұрын
Porn folder 6 GiB too small????
@mldy1
@mldy1 10 ай бұрын
You should use the _Generic keyword instead of the macro for each function
@ariabk
@ariabk 10 ай бұрын
i eat q-tips
@rifkysatyana2415
@rifkysatyana2415 7 ай бұрын
What editor are u using ? Is this VIM or Emacs?
@overloader7900
@overloader7900 10 ай бұрын
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 10 ай бұрын
The 6 level associative TLB is a marvel to behold. It's hashtables all the way down.
@AnimeGIFfy
@AnimeGIFfy 5 ай бұрын
so much echo
@zlatin2830
@zlatin2830 6 ай бұрын
what compiler are you using
@OlliS71
@OlliS71 7 ай бұрын
C is too much work compared to C++.
@jaumeguimeramarquez2244
@jaumeguimeramarquez2244 10 ай бұрын
Came here for yet another AoC 2023. Not disappointed.
@debemdeboas
@debemdeboas 10 ай бұрын
i used to do this a lot when writing buffer encoders/decoders in Turbo Pascal
@l_t_m_f
@l_t_m_f 10 ай бұрын
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 10 ай бұрын
Yes kind of, but it also handles the case where two keys hash to the same index.
@darknais
@darknais 10 ай бұрын
where is the CLITERAL located?
@TsodingDaily
@TsodingDaily 10 ай бұрын
In raylib.h
@mattmurphy7030
@mattmurphy7030 7 ай бұрын
Lmao
@JohnDoe-np7do
@JohnDoe-np7do 10 ай бұрын
Lol that thumbnail matches perfectly with the title
@loogabarooga2812
@loogabarooga2812 9 ай бұрын
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 9 ай бұрын
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 7 ай бұрын
Endianness affects the order of bytes in a field, not the order of fields in a struct
@yooyo3d
@yooyo3d 10 ай бұрын
When you are in doubt, use void*.
@glowiak3430
@glowiak3430 10 ай бұрын
void* goes brrrr
@ingmarfalk3306
@ingmarfalk3306 10 ай бұрын
Should you do aoc in porth ? Would be fun to see :D
@HideoV
@HideoV 9 ай бұрын
why are you so triggered
@nosojdjos
@nosojdjos 10 ай бұрын
Excuse my galactic ignorance, but what's the code editor you're using?
@plushrei5926
@plushrei5926 10 ай бұрын
Emacs i think
@nosojdjos
@nosojdjos 10 ай бұрын
@@plushrei5926 Thanks!
@yaksher
@yaksher 10 ай бұрын
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.
@PragandSens
@PragandSens 10 ай бұрын
Lol no generics
@ukyoize
@ukyoize 9 ай бұрын
I mean, real generics require name mangling
@savantshuia
@savantshuia 10 ай бұрын
17:31 I'm sorry man, T_T
@supergem4845
@supergem4845 10 ай бұрын
How can you do hot reloading in java I thought about using the dynamicClassLoader but the GC doesn't seem to happen correctly sometimes.
@davydorynbaev
@davydorynbaev 10 ай бұрын
hello hello zozzing session
@fluentpwn8065
@fluentpwn8065 10 ай бұрын
holy shit gf2 is cool
@norabelrose198
@norabelrose198 7 ай бұрын
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
@chri-k
@chri-k 6 ай бұрын
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 5 ай бұрын
@@chri-k 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.
@chri-k
@chri-k 5 ай бұрын
@@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
@mariosshadow8533
@mariosshadow8533 2 ай бұрын
@@chri-k I think I see what you're trying to say, but strictly speaking, no. Inside the generic function, the code is very similar, but not identical: a version dereferences from the stack, and other dereferences a pointer given as an argument. What changes dramatically is the prelude to calling the function: You have to make a copy of the type on the argument stack (for architectures that use stack). That grows linearly with the size of the type, but with pointers, it's always just passing a pointer. If you could clarify what you're trying to say, maybe I could understand better.
@chri-k
@chri-k 2 ай бұрын
@@mariosshadow8533 I have re-confirmed that both the preludes and the function content are in fact identical at least under clang (unless the structure is very small and can actually be passed by value)
@umutdogrru
@umutdogrru 10 ай бұрын
the editor you are using looks really nice, what is its name
@ruslansmirnov9006
@ruslansmirnov9006 9 ай бұрын
Emacs
@wlcrutch
@wlcrutch 9 ай бұрын
@@ruslansmirnov9006 Vim is better
@ukyoize
@ukyoize 9 ай бұрын
it's called pico. I reccomend "boku no pico" fork.
@UnrealCatDev
@UnrealCatDev 10 ай бұрын
Hello!
@leschopinesns100
@leschopinesns100 10 ай бұрын
CS student for 5 years, spent 1000€ for my entire scholarship *laughs in french*
@snof7602
@snof7602 10 ай бұрын
can you share discord server here please
@cobbcoding
@cobbcoding 10 ай бұрын
discord link is on the twitch channel
@phitc4242
@phitc4242 10 ай бұрын
I do
@eliseulucenabarros3920
@eliseulucenabarros3920 9 ай бұрын
C IS EVERYTHING
@exnihilonihilfit6316
@exnihilonihilfit6316 7 ай бұрын
It's not my mother, nor your аss.
@ChaotikmindSrc
@ChaotikmindSrc 10 ай бұрын
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 10 ай бұрын
"but generics/templates are a gift from god" It's just crap.
@ChaotikmindSrc
@ChaotikmindSrc 9 ай бұрын
@@IBelieveInCode if seriously think it is a good idea, maybe we didn't find the right way do it now
@suprecam9880
@suprecam9880 9 ай бұрын
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.
@Narblo
@Narblo 10 ай бұрын
What is the point to have a stable build of rust if they force you to use nightly?
@Techgeek002
@Techgeek002 10 ай бұрын
Will you ever make a course for newbeginners
@esepecesito
@esepecesito 10 ай бұрын
Data has types, not variables!
@Eek_The_Cat
@Eek_The_Cat 9 ай бұрын
void* is a crime.
@fattoofittoo7907
@fattoofittoo7907 10 ай бұрын
how to become good problem solver in programming?
@mattmurphy7030
@mattmurphy7030 7 ай бұрын
Practice. Solve 100 Leetcode problems and then you’ll know the answer to your question
@jack-zc3gj
@jack-zc3gj 10 ай бұрын
how exactly is c hot reloadable? cant find anything about this online and it does not seem to work in my testing
@dirrelito
@dirrelito 10 ай бұрын
Check older streams
@charliesumorok6765
@charliesumorok6765 9 ай бұрын
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 7 ай бұрын
And I don’t believe that you can’t find anything because when I search C hot reloading I immediately come to KZbin videos about it and a library that implements it
@michunel7022
@michunel7022 8 ай бұрын
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?
@mattmurphy7030
@mattmurphy7030 7 ай бұрын
Ok zoomer
@iampointless
@iampointless 10 ай бұрын
Что это
@inertia_dagger
@inertia_dagger 10 ай бұрын
a void pointer
@RSchenal
@RSchenal 10 ай бұрын
музыкальный визуалайзер - музиалайзер
@samuraijosh1595
@samuraijosh1595 10 ай бұрын
This content is not for Greeks.
@iampointless
@iampointless 10 ай бұрын
@@samuraijosh1595 i am not greek
I tried React and it Ruined My Life
1:19:10
Tsoding Daily
Рет қаралды 133 М.
I regret doing this...
1:20:07
Tsoding Daily
Рет қаралды 75 М.
Ozoda - Lada ( Official Music Video 2024 )
06:07
Ozoda
Рет қаралды 17 МЛН
Spongebob ate Patrick 😱 #meme #spongebob #gmod
00:15
Mr. LoLo
Рет қаралды 20 МЛН
когда не обедаешь в школе // EVA mash
00:57
EVA mash
Рет қаралды 3,7 МЛН
pumpkins #shorts
00:39
Mr DegrEE
Рет қаралды 54 МЛН
They Made a Sequel to C
1:53:24
Tsoding Daily
Рет қаралды 93 М.
Configuring Emacs on My New Laptop
2:00:09
Tsoding Daily
Рет қаралды 46 М.
Andrew Kelley   Practical Data Oriented Design (DoD)
46:40
ChimiChanga
Рет қаралды 109 М.
Optimizing with "Bad Code"
17:11
Kaze Emanuar
Рет қаралды 213 М.
Why I Use C | Prime Reacts
13:00
ThePrimeTime
Рет қаралды 160 М.
Reverse Engineering Data Files
1:59:16
Tsoding Daily
Рет қаралды 39 М.
Arenas, strings and Scuffed Templates in C
12:28
VoxelRifts (PixelRifts)
Рет қаралды 87 М.
Hash Table in C
2:11:31
Tsoding Daily
Рет қаралды 65 М.
bulletproof❌ Nokia✅
0:17
AGENT43
Рет қаралды 34 МЛН
Как удалить компромат с компьютера?
0:20
Лена Тропоцел
Рет қаралды 2,1 МЛН
Китайцы сделали телефон БАЯН
0:14
Собиратель новостей
Рет қаралды 1,5 МЛН