Тёмный

why do header files even exist? 

Low Level Learning
Подписаться 591 тыс.
Просмотров 369 тыс.
50% 1

So why do we use header files? Are they just there to look pretty? Is there actually a reason that we include them in all the code we write? In this video we explore how the compiler works, how the linker works, and how header files tie the whole process together.
🏫 COURSES 🏫 Learn to code in C at lowlevel.academy
📰 NEWSLETTER 📰 Sign up for our newsletter at mailchi.mp/lowlevel/the-low-down
🙌 SUPPORT THE CHANNEL 🙌 Become a Low Level Associate and support the channel at / lowlevellearning
How Does Return Work? • do you know how "retur...
🔥🔥🔥 SOCIALS 🔥🔥🔥
Low Level Merch!: lowlevel.store/
Follow me on Twitter: / lowleveltweets
Follow me on Twitch: / lowlevellearning
Join me on Discord!: / discord

Наука

Опубликовано:

 

15 сен 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 514   
@LowLevelLearning
@LowLevelLearning Месяц назад
wanna get good at programming? check out lowlevel.academy and use code THREADS20 for 20% off lifetime access. or dont. im not a cop
@cawkcheck
@cawkcheck 9 месяцев назад
idk man
@fxiqval
@fxiqval 9 месяцев назад
+1
@Dev-Siri
@Dev-Siri 9 месяцев назад
same dude.
@abcdefg-nu4xj
@abcdefg-nu4xj 9 месяцев назад
same i'm literally shaking holding my JS teddy bear
@klebleonard
@klebleonard 9 месяцев назад
now you know man
@livingcodex9878
@livingcodex9878 9 месяцев назад
great
@Proferk
@Proferk 8 месяцев назад
in short: Header files are just C files whose contents get copied/pasted into the place where you #include them. This copy/pasting is done by the preprocessor program, which runs before the compiler (technically nowadays the preprocessor and compiler are usually in a single program, where the compiling stage is done after the preprocessing stage). Header files just contain "forward declarations" to tell the compiler that even though the function's code isn't anywhere to be found in the C file being compiled, the linker will afterwards add the code of this function from another file. This is necessary to tell to the compiler, because otherwise it would complain that the there's no code for the function written (i.e. the function isn't defined). Header files just tell a compiler "hey I know you can't find this function's code (definition) anywhere, but trust me, the code of this function will be linked into the program by the linker afterwards from another C file".
@-MG24X-
@-MG24X- 25 дней назад
Your explanation is understandable,Thanks mate
@DanielTredewicz
@DanielTredewicz 9 месяцев назад
You can also use a header files to declare structs w/o exposing their fields (you define them in the source file). That way you ensure that users of your library operate on structs only through pointers to them and API you provided, so you achieve encapsulation.
@foxwhite25
@foxwhite25 9 месяцев назад
public in any language: hello
@EdKolis
@EdKolis 9 месяцев назад
Sounds like security by obscurity. Someone will eventually guess the names of your "private" fields!
@MD-vs9ff
@MD-vs9ff 9 месяцев назад
​@EdKolis it's not security, it's what the developer is able to use in source code. Of course there's ways to get around it, but the point is just to make it harder to do something you don't want them doing.
@ruanpingshan
@ruanpingshan 9 месяцев назад
Is that what they call the Pimpl pattern?
@TheRPGminer
@TheRPGminer 8 месяцев назад
Won't it cause allocation problems? When sizeof(struct) lies to you about real size? Or am I wrong somewhere?
@HairyPixels
@HairyPixels 9 месяцев назад
Header files are only there because it makes it easier for the parser. They are technically not needed but this is the legacy of C and other languages so it's stuck around. I don't mind them personally but it's hard to justify their existence because removing them is just an technical problem which can be solved with a little effort.
@kerimgueney
@kerimgueney 9 месяцев назад
I was just thinking the same. If one is naughty, one could completely ignore header files and just use implicit declarations all around. C could use an actual module system like Rust but I suspect that's not going to happen any time soon. I heard C++20 introduced a module system, but then you're programming in C++ .... or some subset of it.
@atif1538
@atif1538 9 месяцев назад
i dont get it, how would certain functions run then?
@kerimgueney
@kerimgueney 9 месяцев назад
@@atif1538 the compiler would just create an implicit declaration for any external function, which will always look like int functionName() (always an int and empty parameters). The linker will then just try to match the function name to what it can find in the libraries. If you pass the correct arguments to the functions and handle its return value correctly, everything should work just fine.
@torarinvik4920
@torarinvik4920 9 месяцев назад
@@kerimgueney Wow, did not know that. Thanks for info!
@atif1538
@atif1538 9 месяцев назад
​@@kerimgueneyso u could just include another .c file with the definitions and wouldnt need a header file?
@JkaBG
@JkaBG 9 месяцев назад
Dealing with header files in c/c++ feels like doing the job of the compiler. I understand the need of a header file when linking with dynamic/static library. BUT in 99% of header files I wrote I also wrote the source file.
@wiktorzdrojewski890
@wiktorzdrojewski890 9 месяцев назад
Having implentations in headers leads to longer compile times, separate file.cpp can be compiled to object files indelendent of other code
@rursus8354
@rursus8354 9 месяцев назад
The header files will be useful if you get a new task that takes say 6 months and then need to return to the task, and also if you rise in the career and someone else needs to understand what you coded. Just regard them as your own well structured notes for yourself (and others).
@DoubleM55
@DoubleM55 9 месяцев назад
Dealing with header files is one of the reasons why I decided to go with Java development career instead of C/C++.
@MechMK1
@MechMK1 9 месяцев назад
@@rursus8354Yes, that is what comments are for. In the best case, the header just says what the source file says. In the worst case, the header is a complex maze of ifdefs that are impossible to navigate.
@MI08SK
@MI08SK 9 месяцев назад
When C and C++ were developed there wasn't such concept as module
@rafaelkuhn
@rafaelkuhn 9 месяцев назад
Be careful with those $(pwd) calls, they undergo bash word expansion and can be broken into two different arguments if your path has a space in it, always quote those things with double quotes ", same if you were to do "$PWD" (just reading the variable PWD instead of running the pwd command in a subshell)
@Blue-Maned_Hawk
@Blue-Maned_Hawk 9 месяцев назад
Fuckin' sh, man. How'd it catch on?
@4.0.4
@4.0.4 2 месяца назад
There are so many things that break if you have a space in the path for this reason!
@3snoW_
@3snoW_ 9 месяцев назад
Something you didn't mention is that header files are included in the precompiler phase. The line _#include__ "myheader.h"_ is basically an instruction that tells the precompiler to replace this line with the contents of _myheader.h_ . This is why header inclusion is a # command, and also why headers start with a #ifndef command, to make sure that the same header isn't included more than once by the precompiler. It also means that you don't have to limit yourself to declare functions on the header file, you can technically write any code inside a header file and it will compile just fine, though it can lead to problems if multiple source files use the same header (multiple definition error).
@lilyyy411
@lilyyy411 9 месяцев назад
inline my beloved
@davidfrischknecht8261
@davidfrischknecht8261 9 месяцев назад
Headers could also start with a "#pragma once" command.
@dimitar.bogdanov
@dimitar.bogdanov 8 месяцев назад
> though it can lead to problems if multiple source files use the same header (multiple definition error). But why? Doesn't #ifndef/#pragma once fix this?
@Scotty-vs4lf
@Scotty-vs4lf 8 месяцев назад
@@dimitar.bogdanov the ifndef/pragma prevents you from getting multiple definitions in one translation unit, but if you link with another compiled source file that included the header then you would basically be including that code twice, because each source file has its own copy of the header
@sly-shot
@sly-shot 8 месяцев назад
@@davidfrischknecht8261 #pragma once is nonstandard.
@twenty-fifth420
@twenty-fifth420 9 месяцев назад
I know someone said you are a gem for embedded, but you are also one for game dev and low levelers with hardware restraints. I love it. I am just a little to deep, but I saw 'header file' reading the raylib documentation as being modular and interchangable. And I would be lying to say I had any clue what a header file or what a C file with a header file really...means. This video clears up alot of over complicated imagined semantics. Thanks!
@ex-xg5hh
@ex-xg5hh 8 месяцев назад
Instead of "why do header files even exist" you explained how header files work, but the question from the title of the video still stands. You may have noticed that header files are almost exclusive to C/C++ languages, other languages somehow don't need them. So why do header files even exist? For those wondering, header files exist mostly for historical reasons. Since memory was very limited back when C was developed, compilers couldn't afford to keep track of modules themselves, so it became the job of the programmer. Modern compilers are far less hardware restricted, which allows them to favor developer experience over efficiency.
@user-lh6ig5gj4e
@user-lh6ig5gj4e Месяц назад
Your channel is making me a better programmer one video at a time. I'm really thankful for that since I mostly just learned to use programming as a tool to get things done, but as a computer architect with a mathematics background I really prefer to understand how things really work. So a huge thanks from me to filling these gaps one step at a time!
@charlesmayberry2825
@charlesmayberry2825 6 месяцев назад
This reminds me of my earliest programming experience where it was still common to do the compile and linking semi manually. It was also common to have an automation, but still when I started, and this was not as long ago as you might think, manually compiling and linking simpler programs was still considered common practice.
@0xmmn
@0xmmn 2 месяца назад
I love your work man, although I know this info already but I'm enjoying watching you explaining it with this much practical details.
@sb_dunk
@sb_dunk 9 месяцев назад
Great video, I've used C a bit, not loads, and you explained so many things that I just kinda accepted without really fully understanding.
@drditup
@drditup 3 месяца назад
6 years after completing classes, i learned why and "" are used in the includes.
@T33K3SS3LCH3N
@T33K3SS3LCH3N 8 месяцев назад
Basically the implicit function declaration already knows the arguments and return of the function. If compiled to assembly/binary, it can pass its parameters into appropriate registers and read back an expected return from the return register. But the binary also needs to know the address of the function, to jump there and continue with the code execution of that function. To find out this address, the files need to be linked. If no matching function can be found at this time, the linker can only give up. In many modern strongly typed languages and IDEs, we would expect the IDE to already have done that lookup in real time as we type the code, so we may not even be allowed to start compiling.
@abghany4761
@abghany4761 9 месяцев назад
Can you make more videos about the building process? I really enjoyed this one
@capability-snob
@capability-snob 9 месяцев назад
A great way to show this is with objdump output on .o files, .so files, and executables. It might be fun to do one about why the order of linker arguments matter (it's an iterative process!)
@mihiguy
@mihiguy 9 месяцев назад
Technically, in the last step you could just list all your .c files instead of .o files, but it would mean you have to compile both files every time even if only one of them changes.
@diegoj4382
@diegoj4382 2 месяца назад
It would have to be huuuuge to make a real impact in todays processing speeds
@Xetarine
@Xetarine 8 месяцев назад
Btw, for linker paths in e.g. proprietary programs, patchelf from the NixOS project exists. It lets you change paths to libraries in standard Linux ELF files, which they have to use as that distro doesn't use /usr/lib.
@thisaintmyrealname1
@thisaintmyrealname1 Месяц назад
thank you, you not only explained me header files but also the point of using Makefiles towards the end ❤
@d3c3pt1_n
@d3c3pt1_n 7 месяцев назад
I have been looking for a good video about this for a long time 😂 thank you!!
@rtiodev
@rtiodev 3 месяца назад
Thank you very much, I literally dealt with tons of compiling issues when programming in go using the FFI and realized that I have never understood it correctly.
@mytechnotalent
@mytechnotalent 9 месяцев назад
great definition, this was the first thing I had to figure out decades ago with circular dependencies
@CallousCoder
@CallousCoder 9 месяцев назад
I’ve never found header files an issue, if anything I find them a blessing. A nice readable prototype of an implementation for a function that I don’t want to know the implementation details from. I hear everybody complain about it and it makes no sense to me as to why. I hate those people who do implementations also in header files.
@candrar2866
@candrar2866 9 месяцев назад
Just to add if you don’t mind. I remember Bob C. Martin and someone else explains header file being similar to Go/Java interface and it could be made to serve the purpose of hiding private functions. Lately though I have doubts about the abstraction layers itself. I encounter most of the times hiding the details behind interfaces makes behaviour of code harder to understand but that’s anecdotal. While at the same time, there is no way to code without abstraction.
@CallousCoder
@CallousCoder 9 месяцев назад
@@candrar2866 nice addition! Usually I don’t hold uncle Bob in a very high regard but a header can be seen as an interface definition. Now that’s the difference between Java and C++ you have all the definition public, private, protected. Which shouldn’t be needed really but back in 1970 when C was created the sole purpose was to develop operating systems. Those systems didn’t have the power to quickly scan binaries to find functions and bind to them. Because reading binaries was so slow. So basically the whole header files started as a helper for underpowered linkers. These days we can do that without effort and the idea of a header file is dropped in all modern languages. But I do like a header file strictly as an interface like Uncle Bob sees them. You get a binary library and a header file and you know exactly how to call the functions.
@mihaicraciun8678
@mihaicraciun8678 9 месяцев назад
I fully agree
@imaginerus
@imaginerus 9 месяцев назад
You know you can just collapse the function contents in any proper editor to get basically the same information? IIRC it's ctrl-K ctrl-0 in VSCode.
@CallousCoder
@CallousCoder 9 месяцев назад
@@imaginerus then you will need to send the code along and compile the whole code. The idea of libraries is that these are already in binary format.
@brandoncazares8452
@brandoncazares8452 9 месяцев назад
Very helpful video, this helped a lot. Thanks, dude.
@1oglop1
@1oglop1 8 месяцев назад
Awesome channel, fills in a lot of my knowledge gaps efforlesly!
@hoodie_cat
@hoodie_cat 9 месяцев назад
07:12 Doing `$(pwd)` instead of `$PWD` is like doing `cat file | grep pattern` instead of `grep pattern file` 💀
@johnmurray1889
@johnmurray1889 2 месяца назад
Wow, this is such great information that I found a week after I needed to know it.
@sid6576
@sid6576 9 месяцев назад
Great video, learned a lot.
@m1geo
@m1geo 9 месяцев назад
Great video! Nicely presented! 👌
@sasikanthkola9925
@sasikanthkola9925 20 дней назад
I just started coding, into this video around 2 min, already subscribed...❤❤
@herberttlbd
@herberttlbd 4 месяца назад
"Declaration" and "definition" have very specific meanings in C. You got it right at one point in the video, where you said the declaration is in the header but not the definition, but you kept using the wrong terms throughout the rest of the video. K&R assumed an implicit declaration of unknown functions as returning an int - parameters were not part of the signature - but ANSI made declarations for functions mandatory and added parameters.
@coolbrotherf127
@coolbrotherf127 8 месяцев назад
One thing is that all the code in the header files does get compiled in with the rest of the code which is why really big header files, or source code files with lots of headers take a while to compile since there's a lot of hidden code being analyzed by the compiler.
@grimvian
@grimvian 4 месяца назад
C learner here. Great video. I use #pragma once and intend to have declarations in the header files, but I often struggles in a projects, where I have multiple .c and .h files. I think of two ways to deal with that. Use static more and move some of the declarations to the related .c file.
@markrosenthal9108
@markrosenthal9108 2 месяца назад
For data that is not self-describing, you need a way to share the common structure across multiple source code files. It's also helpful for sharing common source processing directives. This concept originated before computers with "boilerplate" text and copy books and the term "copy book" was adopted by Amazing Grace for Cobol.
@colinmaharaj
@colinmaharaj 8 месяцев назад
Header fights create a prototype declaration of the interface to a full actual function. Only at link time you'd need the code for the function. Ultimately the whole compilation process will be faster, and gives you a full correctness check before linking.
@alexaneals8194
@alexaneals8194 3 месяца назад
Very well rounded discussion of header files. Although, you could have added more detail like pragma options and such, I like the way you discussed it since it's easier for beginners to understand without all of the details they can learn later.
@stef9019
@stef9019 8 месяцев назад
Awesome explanation! Thanks!
@JakobWierzbowski
@JakobWierzbowski 9 месяцев назад
Great explanation. Thank you
@crrodriguez
@crrodriguez 7 месяцев назад
For future viewers.. newer compilers will treat 1:39 as an error (as if -Werror=implicit-function-declaration) not as a warning as t is invalid c99..the link step will not ocurr.
@wb7779
@wb7779 9 месяцев назад
Wow, I really like the shirt he's wearing. Assembly language just got more interesting.
@sritharan20
@sritharan20 9 месяцев назад
man your awesome, you just answer the most intricate questions devs have. I just had this doubt today and you video came in. Great service. Thx again.
@menaced.
@menaced. 9 месяцев назад
My first Cpp project was a game-engine following theCherno’s tutorial to start and I learned how to use header files kinda naturally i never even thought about “why” im doing i just new when to use it
@chry003
@chry003 9 месяцев назад
Actually, I started learning c++ the exact same way, about 2 years ago with his sparky series.
@chry003
@chry003 9 месяцев назад
Are you still working on that!?
@theantipope4354
@theantipope4354 6 месяцев назад
I *really* wish this video (or something equivalent) had existed when I first started learning C in the 80s, because this stuff confused the hell out of me at the time, & was never explained properly in the texts I was learning from.
@heanz
@heanz 2 месяца назад
love your channel
@BerayTriangle
@BerayTriangle 9 месяцев назад
At first, I didn’t appreciate headers, I considered them cumbersome. I always thought that you’re repeating yourself. Then I started writing a rendering engine, and oh are they a lifesaver. Declaring one header file that’s used across 4 APIs has saved me a lot of time and effort instead of writing one for each.
@MagpieMcGraw
@MagpieMcGraw 7 месяцев назад
When I was doing C I used unity build. Instead of using header files I just included .c files directly. I had my main .c file that had the main loop, and included all the other files into that. It worked beautifully. This method has a downside and an upside. Downside is that you can't tell what each file depends on. The upside is that you have to figure out how to avoid a circular reference, which makes your code more disciplined and organized.
@xarisfil58
@xarisfil58 2 месяца назад
"Returns a Client Star" instead of saying a pointer to a clients struct. This is how terror of pointers starts
@dhyey2316
@dhyey2316 5 месяцев назад
This video was just perfect
@John-yg1cq
@John-yg1cq 5 месяцев назад
Another interesting observation is that a C header file works as an "interface" type. Whereas in C++ or Python "base class", a Rust trait, or a C# interface, in C you have .h files. It describes any object types (structs with or without typedefs) and the (virtual) procedures that are available in the module. An accompanying .c file or Feature Test Macro (for single-implementation header files) can be added to choose the implementation. This way, a .h file can define a bunch of functions, but for instance you could implement one .c file per platform. The .h file is the abstract class/interface/traits, the .c file is the derived class/inteface implementation/impl. C was data-object oriented driven from the start.
@vmscode
@vmscode 9 месяцев назад
A video explaining pointers in the context of structs and vectors being passed to function would be great (What is the best way to access the value of a struct/array and assign it to another struct or variable inside of a function for example...), also one on cmake and best practices when developing with C would be awesome as well, just some suggestions! Thank you for the helpful videos!
@SzBenedek2006
@SzBenedek2006 5 месяцев назад
Exactly the video I needed.
@UltimatePerfection
@UltimatePerfection 2 месяца назад
Headers are basically here to make compiling easier. They're a remnant of the past that stuck around. You see, the early C compilers were dumb so if you tried to call a function that was declared later on in the source, they couldn't find it. Sometimes you could solve this by shuffling the functions around, but sometimes it didn't work when the functions depended on each other. (e.g. Function A needs to call function B that in turn either calls Function C or function B again in some recursion scenario). To solve that dumbness of the early C compilers, the header files were invented where all the functions would be declared beforehand so the compiler won't think that a function that exist, doesn't. Nowadays, the compilers such as GCC and MSVC are actually pretty smart about declarations and can find the function that was declared later on in the code, but the header files stuck around.
@spidertyler
@spidertyler 9 месяцев назад
Isn't it simply because these source files actually don't know about each other? Each unit is compiled separately, only linking at the ends brings those units together.
@paradoxicalegg6112
@paradoxicalegg6112 9 месяцев назад
THANK YOU I NEED THIS
@EngineerNick
@EngineerNick 2 месяца назад
I am currently porting some stuff to rust that uses a headerfile that you are supposed to include multiple times, changing other state betweentimes so that you can declare multiple versions of a struct. This is pure insanity and should never have been posible.
@norbert.kiszka
@norbert.kiszka 2 месяца назад
9:45 You can compile it in easier method in one go. Instead of creating separate objects, give a gcc all the .c (and .o) files.
@brianviktor8212
@brianviktor8212 2 месяца назад
Can't all of this be automated? If I'd have to use C, I'd create some application in C# to do all of that, including auto-generate header files. It must be a pain to do that manually repeatedly.
@livingcodex9878
@livingcodex9878 9 месяцев назад
This is a gem.
@theIvex
@theIvex 9 месяцев назад
so to define files to liker I need to use GCC for example or any other compiler, is that right?
@JDAndNightrain
@JDAndNightrain 9 месяцев назад
Can you talk about the pimpl idiom? I've seen it discussed as a way to hide implementation details, but I've never understood it.
@alexandernordin3399
@alexandernordin3399 9 месяцев назад
Thank you for the helpful video! At 7:52, I think you misspoke by saying "defined" instead of "declared".
@rowdyriemer
@rowdyriemer Месяц назад
It's funny - when I write C++, I really like that C++ has headers. When I write C#, I really like that it doesn't have headers.
@alex-krycek
@alex-krycek 4 месяца назад
Hello LLL! Could you explain what happens in the linking process? What does it do to the object file? How can the executable locate the library code at runtime to execute it? I like to know how this whole world of references and dependencies works in Linux. Thank you very much for sharing your knowledge, I really appreciate it.
@kevinyonan2147
@kevinyonan2147 6 месяцев назад
according to Wikipedia of C's history: *The preprocessor was introduced around 1973 at the urging of Alan Snyder and also in recognition of the usefulness of the file-inclusion mechanisms available in BCPL and PL/I. Its original version provided only included files and simple string replacements: **#include** and **#define** of parameterless macros. Soon after that, it was extended, mostly by Mike Lesk and then by John Reiser, to incorporate macros with arguments and conditional compilation.* So if you hate the preprocessor, blame Alan Snyder.
@codegeek98
@codegeek98 3 месяца назад
Is it possible to do dynamic linking without having a copy of the .so at _compile_ time, only based off metadata?
@Ozzymand
@Ozzymand 9 месяцев назад
How did you get your vim? nvim? to look like that? Do you have a tutorial for it?
@dwijdixit7810
@dwijdixit7810 3 месяца назад
This is one of those videos with really clickbaity names, but real content!
@stachowi
@stachowi 9 месяцев назад
This was fantastic.
@MixeuDev
@MixeuDev 8 месяцев назад
which linux distro u use and which ide do u use? thx!
@TechwithHari
@TechwithHari 9 месяцев назад
We need a video on makefiles!
@uplink-on-yt
@uplink-on-yt 9 месяцев назад
Object files should technically be shipped by closed source software that embeds (rather than link externally) LGPL code so you can compile and link your own copy of the LGPL code, but I'm yet to see anyone do that.
@devluz
@devluz 9 месяцев назад
3:11 Can you have another look at this? I think this was suppose to say "link -> dll" for windows? As far as I know static libraries (*.a / *.lib) are not linked at all. e.g. on linux the command "ar" will just bundle several *.o files into a single *.a. No linker involved. It would be great to see a deep dive in how static and dynamic libraries work in detail.
@afterschool2594
@afterschool2594 8 месяцев назад
I think header file is also the way to make function implementation private/hidden from the end user
@Sakapaka
@Sakapaka 8 месяцев назад
how does including the client.h in code.c give access to the definitions in client.c?
@ctrlz4439
@ctrlz4439 9 месяцев назад
Please remember 40 years back making it easier for computer to compile was extremely important. I remember old grumpy programmers complaining about inefficiency of high level languages (C)
@johnmarks714
@johnmarks714 8 месяцев назад
Fantastic video.
@ZipplyZane
@ZipplyZane 8 дней назад
I was expecting this to answer why they decided to create these standard headers and not bake what is in them into the language. I assume it's a historical thing, possibly combined with just how low level C is intended to be. They didn't want to have code that is only added if it is used baked into the language itself.
@benfowler1134
@benfowler1134 2 месяца назад
Linking is an interesting but very complex subject for people interested in low-level stuff.
@drstrangelove09
@drstrangelove09 4 месяца назад
10:00 "is getting *_ran_* " -> NO, not "ran" -> it is "run" ... why do so many people mess this up?
@FireChronos
@FireChronos 9 месяцев назад
That shows how they work, but I never really got why the compiler didn't just handle all of that to begin with. Why is another file necessary when it's just duplicating code that was already written? Wouldn't it make more sense to DRR?
@amzabdrahim3350
@amzabdrahim3350 9 месяцев назад
thank you so much for explaining this, i didn't get it each time someone tries to explain it to me but you did explain it so good! you are a geat teacher, thank you
@bobtoad8601
@bobtoad8601 Месяц назад
The question is why modern compilers cannot generate those header files and still rely on manually write them
@Ashish_Bisht
@Ashish_Bisht 9 месяцев назад
pls make a video on kernel headers.
@mohitkumar-jv2bx
@mohitkumar-jv2bx 9 месяцев назад
Video was great. i was just trying out rust FFI and i don't know much about c. and i came on YT and found this at top. Thanks
@rodgomesc
@rodgomesc 9 месяцев назад
I'm excited to start the course but I'm experiencing a problem. When I try to watch any video other than the introduction, I get redirected to the purchase page. (I already bought the product) Can you kindly check what's happening?
@johnmarks714
@johnmarks714 8 месяцев назад
Please do a video that analyzes C++ objects at the assembly level
@cparks1000000
@cparks1000000 9 месяцев назад
This doesn't explain WHY the header file exists. It explains WHAT the header file is used for...
@kostadingramatikov9692
@kostadingramatikov9692 3 месяца назад
Bro how can't you understand the purpose of a library. Have you programmed in python? The reason why it exists is first because you need some order and no matter how much you order a file when it has thousands of lines of code its a bit messed up. And secondly its really convenient to take a functionality that someone already made and use it right away.
@stefano_schmidt
@stefano_schmidt 23 дня назад
@@kostadingramatikov9692 read his comment again
@ujjawalsinha8968
@ujjawalsinha8968 9 месяцев назад
Can you please explain stb style header files?
@NotXike
@NotXike 9 месяцев назад
Why did you have to set an environment variable at 7:37? Was the call to gcc at 7:20 not sufficient to make the association?
@kerimgueney
@kerimgueney 9 месяцев назад
I don't think the gcc call is enough since lowlevelmath is a shared/dynamic library. During run-time you got to tell the link loader where to find all necessary shared libs. It's kind of like the PATH environment variable for libraries
@seabrookmx
@seabrookmx 9 месяцев назад
No, because the add function was in a shared object (.so) which is loaded at runtime (dynamic linking). Later in the video he uses .o files (static linking) so it's not necessary. He kinda glossed over that bit.
@devluz
@devluz 9 месяцев назад
How dynamic libraries such as *.so / *.dll are found is kind of platform specific. e.g. in windows DLL's are automatically searched in the application folder and a bunch of other folders (super unsafe. google dll injection). On Linux you can embed a "RPATH" into your executable that tells linux where to find the *.so file or you use the environment variable as shown in the video. Note that this gets even more complicated: Android, iOS and co all use "rpath" but in very different ways.
@frittex
@frittex 9 месяцев назад
ok but where do i get this shirt?
@reynoldskynaston9529
@reynoldskynaston9529 9 месяцев назад
First time I’ve really understood the linker vs compiler
@Debaser36
@Debaser36 3 месяца назад
Nice video. Maybe you do some videos about this topic in general in the future, so I have some constructive criticism (even if it was a while ago). If you don't, then maybe these points will shine some light on things for other people: - you could mention, that a #include directive really does what the name tells you: it INCLUDES the file after the "#include" in the file, where the '"include" is. This means, that it COPIES the entire file into your file. I personally find this (in my opinion very smart) solution to the problem of declaring functions quite interesting. - you could SHOW some assembly created without optimization. On the one hand from the .obj files, on the other hands from the linked executables/libraries. When I saw that for my first time, a lot of things got more clear for me. - you could somehow illustrate the ACTUAL linking of symbols (and what does "symbol" even mean? 🙂 ). Maybe this is somehow a difficult topic, nontheless very interesting. - this last point is also a good cliffhanger to go IN-DEPTH on how the CPU really "executes" functions. How do parameters work, how does the OS and consequently the CPU "know", what to return to where, and what to take from where to what as arguments?
@Popart-xh2fd
@Popart-xh2fd 3 месяца назад
What are the full path of the folders?
@JoseFerreira-un2cl
@JoseFerreira-un2cl 9 месяцев назад
How are you able of highlighting the text both in Vim and in the terminal so fast, even when the cursor seems to be somewhere else? Care to share your tricks?
@travisporco
@travisporco 9 месяцев назад
did you pronounce - as "tack"?
@minirop
@minirop 9 месяцев назад
damn! continuity error at 1:33 (the name of the .o file changed 🥲)
@talkysassis
@talkysassis 5 месяцев назад
I'll tell you what I think would be a good dependency system for programmers You make a lib with a main file (not to execute, just with the functions you'll provide) You compile that to a .clib file that is bytecode You import the clib file in your program and use the libs You compile everything and you get a binary with some .so for the libs This would be a lot easier to use, create and distribute libs without the mess that is build systems. If there's a language like this please let me know.
@sonuaryan5287
@sonuaryan5287 6 месяцев назад
Okay can we link functionality over different computer let's say add stay on server A subtract on B and I am calling them on server C. In java we can do it using rmi. And in c I tried using callback function binded to target command enum. Any other way?
Далее
the truth about ChatGPT generated code
10:35
Просмотров 214 тыс.
why do void* pointers even exist?
8:17
Просмотров 329 тыс.
BETTER Header Files and Preprocessor Debugging
24:26
Просмотров 68 тыс.
Short introduction to header files in C
13:34
Просмотров 80 тыс.
why are switch statements so HECKIN fast?
11:03
Просмотров 385 тыс.
31 nooby C++ habits you need to ditch
16:18
Просмотров 731 тыс.
How A Steam Bug Deleted Someone’s Entire PC
11:49
Просмотров 903 тыс.
Naming Things in Code
7:25
Просмотров 2 млн
Should you learn C++?? | Prime Reacts
20:29
Просмотров 321 тыс.
Rust Functions Are Weird (But Be Glad)
19:52
Просмотров 127 тыс.
Мечта Каждого Геймера
0:59
Просмотров 1,7 млн
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00