Tips for C Programming

Поділитися
Вставка

КОМЕНТАРІ • 480

  • @constantinhirsch7200
    @constantinhirsch7200 10 днів тому +125

    0:55 "People's perception seems to be that C is so spartan that you need to build everything yourself from scratch"
    21:14 "Implementing Runtime Bounds Checking yourself is incredibly straightforward"
    hahaha

    • @h3l_l
      @h3l_l 10 днів тому +9

      nga just dont use c😭
      people come to c when they want a simple, barebones, super flexible language.
      if you really want all the fancy futures just go continue playing with python and java

    • @Nightmare200X
      @Nightmare200X 10 днів тому

      Basically this.... coming from someone who has been used C professionally... for many years. Just go to C++ or learn Rust.

    • @UnrealCatDev
      @UnrealCatDev 9 днів тому

      @@h3l_l I come to C only because it's the best for me but idk

    • @h3l_l
      @h3l_l 9 днів тому

      @UnrealCatDev how do you know it's the best for you?

    • @UnrealCatDev
      @UnrealCatDev 9 днів тому

      @ I know and like it the most so I just think (or lie) to myself that it's the best

  • @sirfloppa5820
    @sirfloppa5820 12 днів тому +140

    "Although it sounds like some complex thing, it actually is very simple."
    That's gotta be this channel's motto.

    • @nicbarkeragain
      @nicbarkeragain  12 днів тому +14

      I have noticed I've said it a few times, it is true of many things, though 😁

    • @carvoloco4229
      @carvoloco4229 10 днів тому +2

      Barely an inconvenience!

  • @ConnectionRefused
    @ConnectionRefused 11 днів тому +74

    This is great! More videos like this please!
    I've been falling in love with C after years of programming higher level languages - BUT I keep running into rough edges which make me think I can't use it seriously for production work.
    Then I hear people like you and Casey Muratori saying that there are workarounds for these rough edges which make C as ergonomic and almost as safe as more modern languages. The problem is that the workarounds are mostly tribal knowledge shared only amongst small groups of very dedicated C programmers (mostly game industry veterans).
    Your skill at aggregating and explaining this type of knowledge to C-curious programmers like me is world class, and I hope you keep making content like this.

    • @nicbarkeragain
      @nicbarkeragain  11 днів тому +18

      That is so reassuring to hear, thank you!
      And I totally agree, this video is only 30 minutes or so, but it's summarising things that took me years to pick up and properly understand. I think as an industry and profession we've struggled a bit with making sure that hard won knowledge is passed on to the next generation, rather than lost.

  • @milo3733
    @milo3733 12 днів тому +119

    I subscribed after the clay video and I've never been happier to see a video pop up on my feed!! this is exactly the type programming content youtube needs

    • @nicbarkeragain
      @nicbarkeragain  12 днів тому +14

      Thank you! The response to the Clay video was partly why I made this - so many people saying "wait, C looks like this?" made me realise that many people aren't that familiar with how nice C can be to work with 🙂

    • @anantakesharipanda4085
      @anantakesharipanda4085 11 днів тому +1

      Same! Found Nic after Clay. Watched the Hash map video entirely even though I knew all it already since university days.

    • @aarorissanen930
      @aarorissanen930 11 днів тому +1

      @@nicbarkeragain Happy to see you educate people on this elegant language. From one C lover to another.

    • @bsdooby
      @bsdooby 11 днів тому +1

      Really great videos, and great presenter

  • @Kokurorokuko
    @Kokurorokuko 12 днів тому +55

    You're a good seller. You really make me want to try to do something in C.

    • @toby9999
      @toby9999 12 днів тому +2

      I've been using C for 30 years, but I prefer C++ most times, even though I use it very much like C, but I'm taking advantage of some very handy extra features. For example, C strings use fixed size buffers of characters, whereas C++ has a string type (container) as well as sets, maps, etc.

    • @cooltrashgamer
      @cooltrashgamer 12 днів тому +2

      @@toby9999 I believe the string stuff was covered in this video

    • @vxcute0
      @vxcute0 11 днів тому

      @@toby9999 yeah I don't like modern C++, but I like operator overloading, templates (without abuse), constexpr, function overloading, and also I have the option to use the stl if I don't want to write my own datastructures.

    • @einsteinx2
      @einsteinx2 6 днів тому

      @@vxcute0 that’s kind of the problem with C++ right? Everyone only likes some parts of it, but the parts they like are always a different set of parts that only partially overlap haha. With that said I do tend to prefer C++ over C for my projects just for all of the quality of life features.

  • @foxquirk
    @foxquirk 12 днів тому +45

    A tip for printing strings that are not null terminated with printf is to use the precision specifier, with the precision set to * meaning variable. So, something like this:
    printf("%.*s", my_string.length, my_string.chars)

    • @oleksandrnahnybida3167
      @oleksandrnahnybida3167 11 днів тому +1

      i also add macro like str_expand(mystr) which expands to mystr.len, mystr.ptr

    • @Windeycastle
      @Windeycastle 10 днів тому +1

      Thanks, was thinking about that for the custom strings and string-slices.

  • @CollinWilliams-by5cs
    @CollinWilliams-by5cs 3 дні тому +2

    33:00 This is unironically the best explanation of rust lifetimes I've seen, while not even being a rust video. This guy never ceases to amaze me!

  • @PaulPaulPaulson
    @PaulPaulPaulson 12 днів тому +16

    These are very good tips and I agree with all of them.
    They are also applicable when using C++ in a C-like style.

  • @БуравовИлья
    @БуравовИлья 11 днів тому +16

    I would say that "Unity Build" technique not always the best solution. Sometimes you need to separate public and private functions and therefore you would like to have "public" headers and "private" headers (that share your internal functions across other translation units) or static functions.

    • @KevinLyda
      @KevinLyda 11 днів тому +8

      Exactly. C has a file scope that helps in building abstractions.

  • @akosma
    @akosma 11 днів тому +13

    This video is a gold mine. Thanks a lot!

  • @nathanaelmoh5848
    @nathanaelmoh5848 10 днів тому +9

    Regarding memory issues, the value of Valgrind cannot be overstated. For anyone using C I believe Valgrind is a must-have in your tool set.

    • @tech6hutch
      @tech6hutch 9 днів тому +2

      It’s Linux-only unfortunately

    • @einsteinx2
      @einsteinx2 6 днів тому +3

      @@tech6hutch actually Linux and macOS. Also Windows on a technicality if you use WSL, but you’re right there’s no proper Windows support as far as I can tell from a quick search.

  • @JAK4L
    @JAK4L 12 днів тому +13

    Man the quality of your content and videos are underrated. Thank you so much for this video.
    I actually sat down and took notes for this one, thank you!!

  • @cozycoder2317
    @cozycoder2317 11 днів тому +7

    I've seen quite the surge of people being more interested in C and doing things from scratch around twitter and the likes, and there are some popular folks in those circles, but sadly you are the first person I found who seems to have the necessary didactic skills to really cover these topics without coming off as alienating or somewhat arrogant. Kudos, looking forward to what you put out in the future!

  • @soniablanche5672
    @soniablanche5672 12 днів тому +79

    It's funny how similar yet different C and C++ are. C is one of the simplest language, C++ is the most complex language (assuming your using C++ features and not just writing C in C++).

    • @omarassadi2455
      @omarassadi2455 12 днів тому +13

      Having gone down the bootstrapping from baremetal rabbithole, I think I will have to petition against Bjarne Stroustrup ever being reincarnated; I swear to god this one Danish man whom I have never met has inflicted PTSD on me. It was really beautiful going from UEFI to a full C toolchain and system in like half-assed ~100K SLOC, and then by the time I actually had Linux and modern GCC building, I think my process had over 60 stages and something like 30 million lines worth of underlying code (excluding the Linux kernel).
      It's such a shame search engines and general casual terminology group them together constantly, because it makes finding actual, genuine, pure C libraries for specific tasks so much more difficult.

    • @nicbarkeragain
      @nicbarkeragain  12 днів тому +28

      The only real situations in which I find myself writing C++ these days are for Unreal, and generally I end up just writing code that looks like C anyway 😁

    • @Anticitizen666
      @Anticitizen666 11 днів тому +3

      4:29 it baffles me that C++ STILL doesn’t have a full implementation of designated initialisers as far as I’m aware.

    • @craftrumzen2393
      @craftrumzen2393 11 днів тому +3

      I think C# is even more complex than C++

    • @chaquator
      @chaquator 11 днів тому +2

      @@Anticitizen666 designated initializers are in c++20, although you have to keep the order consistent with the type definition

  • @mrp898
    @mrp898 11 днів тому +3

    As someone getting back into C programming after a 20 year break from it your channel is the best I've found recently. Such great content, superbly put together; succinct and professional. Many thanks for all the work you put into your videos. A half hour long video with all the animations, code examples, script, etc. is a lot of work! You should really think about making a full C course and selling it. I would happily pay a decent amount for a full course of quality this consistent.

  • @alkmst-xyz
    @alkmst-xyz 12 днів тому +9

    Man, this makes me want to continue my past game dev projects. Really appreciate you advice! Btw, clay is awesome.

    • @nicbarkeragain
      @nicbarkeragain  12 днів тому +4

      You should do it! Building games completely from scratch is some of the most fun I've ever had programming, it was what first got me addicted to it all those years ago 😁

    • @alkmst-xyz
      @alkmst-xyz 12 днів тому

      @@nicbarkeragain I tried Unity Engine 6 years ago when I had an idea for game, but gave up. I didn't even know how to code at the time,. Since then, I learned how to code and got a job in web+ml domain (still loving it). Being mostly self taught, I always felt I was missing something. Somehow I came upon Primegean, Andrew Kelly, Raysan, Teej, and finally you. The way they talk about software engineering was so different from the typical advice from the enterprise (clean code) world I mostly work in. Couple of months ago, I finally made a tiny game (tetris) in raylib (using C++ for stl). I plan to make a 2d platformer like sometime, but really just for the fun of it.
      I really enjoy your refined videos. Your content has re-ignited my love for C and learning in general. Keep up the great work.
      Firing up the IDE right now :)

  • @Gijontin
    @Gijontin 11 днів тому +4

    The approaches-and-small-tips-for-C video I've been looking for since I started, great video! :D

  • @evyatarshafran5017
    @evyatarshafran5017 11 днів тому +1

    Love hearing the “but it’s actually very simple” catchline. Totally helps me get into a relaxed headspace and understand what the heck is going on! Thank you for the awesome videos, as always!

  • @effsixteenblock50
    @effsixteenblock50 12 днів тому +20

    Another life-changing video - Thanks so much Nic!
    I took a pretty deep-dive a few years ago learning C and x86 32 bit asm concurrently, using gcc, NASM and gdb for tools. I've dabbled in other languages but this experience was by far the most fun I've ever had with computing. For all the detail I became immersed in, I have to admit that I didn't concern myself with which version of C I was using.
    Your video helped explain why I was seeing so many different ways of declaring & initializing structs, for example.
    I'm going to revisit my past work and see what I can do with C99 and your ideas with dealing with strings, memory management etc.
    Thanks again Nic! Your content is much appreciated and valued!

    • @nicbarkeragain
      @nicbarkeragain  12 днів тому +7

      You're welcome, and I very much agree - after a long time working in web companies, getting into lower level programming rekindled my joy for the art form 🙂

  • @ItsRyanStudios
    @ItsRyanStudios 7 годин тому

    Damn this was SO good
    No fluff, just pure value to the last second
    I've been writing a lot of C lately, and was curious what the industry standard is for passing arrays and their associated sizes as function params.
    Love this approach of creating structs to handle it

  • @fluffycritter
    @fluffycritter 11 днів тому +8

    In the video you mentioned you were going to link to things about what's new in C11 and C23, but I don't see them in the description or any pinned comment. I'd be super interested to know, as I haven't kept up with plain C (just C++).
    Also C17 was a thing, which I don't think you mentioned, although it looks like it was just a minor revision to C11 anyway.

    • @nicbarkeragain
      @nicbarkeragain  11 днів тому +6

      My apologies, I forgot 😅 I've updated the description with a great resource describing the new features.

  • @onogrirwin
    @onogrirwin 12 днів тому +53

    C is morally superior to everything except 6502 asm

    • @nicbarkeragain
      @nicbarkeragain  12 днів тому +6

      I love the 6502, Pikuma's NES programming course does a great job of teaching it!

    • @tmbarral664
      @tmbarral664 11 днів тому +3

      Funny you mentioned it…. As I was thinking I have no problem about knowing the size of int, long, short and so on…. Coming from 6502 asm on my Apple //c.

    • @sir.boogie
      @sir.boogie 7 днів тому +1

      There’s a Sybex book on 6502 (green cover) a long long time ago … it was my first intro to learning architecture 😂

  • @JeanYvesBouguet
    @JeanYvesBouguet 9 днів тому +1

    As an old timer C programmer (>30 years ) I must admit that I have been genuinely impressed by the quality of the advices presented in this video. Old timers like me also benefit from such high quality content. Over the years i took a lot of things for granted and migrated to C++ as a way to cover up a number of bad practices in C (such as fragmented memory management ). Absolutely loved it!

    • @BitwiseMobile
      @BitwiseMobile 8 днів тому

      This comment! I am also an old timer. My first coding job was in '92 writing embedded C code for devices. I was a C/C++ programmer for another 8 years until the early 00s when I was contracting with a Microsoft vendor specializing in external Outlook data providers - think getting your Outlook on your Blackberry device, or WAP based phone (most kids won't know what those are :P ). Microsoft gave us some dotnet beta disks, and we rewrote our entire ISAPI layer, which was in C++, in C#. I now use C# mostly for business software, but anything embedded I am going to write in C++. I've recently been looking at Rust, but maybe because C was my first high level language (I taught myself assembler when I was 14) I have a fondness for it. I think Rust seems overly complex. It still hasn't "clicked". I'm trying :P

  • @worldx1091
    @worldx1091 11 днів тому +2

    I love these C videos! These were really nice tips, I would love to see a second part in the future

    • @nicbarkeragain
      @nicbarkeragain  11 днів тому +1

      Never say never, I finished this one and immediately thought of a few more things I should have talked about 😁

  • @talesmm1484
    @talesmm1484 8 днів тому

    If I had come across this video at the beginning of my college, I would have been so happy.

  • @videojones59
    @videojones59 10 днів тому +3

    Nice. I have been programming in C since the 1970's and I teach C in university courses. I watch videos like yours to compare what other people have to say about it with what I usually say. You explained everything very clearly and I agreed with pretty much everything you said, except for the "Unity Build". As far as I am concerned, a primary benefit of splitting things up into headers and source files is for modularity: the header files specify the interface, the source files give the implementation, and one does the best one can to hide the implementation details within the source files; e.g. by using "static" declarations. If you just combine all your source files, there doesn't seem to even any attempt to enforce the hiding of implementation details, and that seems like a serious issue to me.

    • @Windeycastle
      @Windeycastle 10 днів тому +1

      On top of that, larger projects benefit from the header-source file split up by not having to recompile unchanged sourcefiles. Yes, the build-system again becomes more complicated, but with large enough projects, it is good tradeoff.

    • @DanCojocaru2000
      @DanCojocaru2000 9 днів тому

      For small and medium projects, there is no reason to hide implementations. People keep bringing that up as a downside, but it doesn't matter?

  • @bmazi
    @bmazi 11 днів тому +6

    C does have a concept of arrays. Pointer to the first element might be a result of decay. Malloc creates arrays too. This concept goes beyond what programmer assumes because compilers may inspect arrays provenance statically to detect opportunities for optimizations based on whether they can prove that pointer points into array or not.
    These optimizations may conflict with programmer's intentions because mere assumptions about pointer pointing into array aren't sufficient. Intentions should also respect what C standard guarantees; and array specification is a part of it. E.g. the standard doesn't define the result of adding 2 pointers together unless it's specific array indexing math; this lack of guarantee may be utilized by compilers, for example, they may detect possibility of undefined bahvior during this pointer summation and generate code that assumes it doesn't happen.

  • @KoltPenny
    @KoltPenny 10 днів тому +1

    The strings section is very true. This is why i have my own string lib with utf-8 support. Very simple to implement, too.

  • @alphabasic1759
    @alphabasic1759 11 днів тому +2

    As a programmer that started in the early 80 my career was mostly one of using C. It’s still my favorite because of how directly approachable I think it is and the control I have over what my code is doing. One problem with “wrapping” code regardless of whether it’s C or assembly to create a new “better” C is that you automatically make your code harder to support; especially by others you may be working with. You’re created your own code”almost C” that they have to learn. That needs to be considered.

  • @ThickpropheT
    @ThickpropheT 12 днів тому +2

    This is making me excited to pick my n64 project back up and see how many of these things I can apply there!

  • @AloisMahdal
    @AloisMahdal 12 днів тому +3

    This channel just keeps getting better.

  • @Akronsus
    @Akronsus 11 днів тому +14

    as far as i know -Wall does not in fact enables all errors, it enables lots of them, but confusingly not all

    • @oleksandrnahnybida3167
      @oleksandrnahnybida3167 11 днів тому +1

      true, Wall, all common checks, but there are also many checks that may not be suitable for everyone

    • @omarassadi2455
      @omarassadi2455 11 днів тому +8

      Yeah, I generally use -Wall -Wextra as well as various other flags. LLVM does happen to have a literal `-Weverything`, which they seemingly regret ever adding due to the reasons hinted at by the other commenter, namely really annoying false-positives that you generally almost never want.

    • @PhotonCompute
      @PhotonCompute 11 днів тому +1

      @@omarassadi2455 That is very true about -Weverything; some of the reported errors seem to be part of an evaluation for a future C standard.

  • @rontarrant
    @rontarrant 9 днів тому +2

    There are several reasons I switched to the D language: 1) includes are done using the import statement, 2) there are no header files, 3) no allocating necessary, and the garbage collector handles deallocating, although you can take control of garbage collection if you need to. I suspect the main reason so few people know about and use D is because of bad timing and the joke factor. D came along at a time when C++ and Java overshadowed it and when I mention D in polite circles, they start singing the A, B, C song (even though I don't think there ever was an A language.)

  • @eba-pachi
    @eba-pachi 12 днів тому +1

    I was going to make a post with the exact same topics because I've been exploring C recently.
    But I think you just made a much better and accessible video haha.

  • @yeshengwei79
    @yeshengwei79 10 днів тому +2

    The slice part is really interesting! Made me understand how Rust slice is actually implemented. The Arena part is also interesting, but it would be more helpful if you can explain a bit more about it.

  • @Lolinatorishere
    @Lolinatorishere 11 днів тому +1

    C is the literal embodiment of the phrase "Complexity Through Simplicity"

  • @asmogaming6309
    @asmogaming6309 9 днів тому

    I just want to say, your content quality is just so goddam good and educational! Keep up the good works, I am 100% sure you will reach more than 100k or even 500k subs by the end of this years!

  • @horhenrp
    @horhenrp 11 днів тому +1

    I just started a silly C project, these tips are really cool!

  • @cycl0ne154
    @cycl0ne154 День тому

    Cool channel ! Thank you. I stumbled upon it and i find it interessting that alot of things which are called "new" or innovative have been discovered 50 years ago ;-)
    example: the malloc in libc .. if you forget your free() the OS will remove the whole adressspace (incl. heap) .. yes its not nice for you as programmer not giving back your memory, but nevertheless done. In the end of 80s we called the Arena : PoolMemory/-buffer -> you alloc a big chunk of memory, use PoolAlloc to allocate from the pool and in the end you throw away the pool (on error or when you are finished).
    Same with strings.. a precessor of C was B which came from BCPL ... and there we had BStr = BCPL Strings.. which where an struct string { uint8_t len; uint8_t *buffer}; (memorywise: 5,'hello') .. no '\0' at the end, since you knew the size..
    so a first compare of 2 strings was fast: the len.. nowadays you loop through each and then get the len to compare it
    Dont know why often things are lost, just to be reinvented

  • @bertiesmith3021
    @bertiesmith3021 День тому

    An arena allocation/deallocation to manage the memory for a task seems similar to a c++ class with a constructor (to allocate the various elements you are going to use in the task) and a destructor (which tidies them up after your done). Except you don’t have to remember to call the destructor - it happens automatically when the object goes out of scope!

  • @EvelynHill
    @EvelynHill 10 днів тому +1

    Great success will come to you Nic! You make incredibly through and helpful talks!

  • @formulaetor8686
    @formulaetor8686 9 днів тому

    The beauty lies in simplicity of C and thats why I love it and I loved the Clay lib too for the same reason btw! You're amazing dude!

  • @justcorsin
    @justcorsin 10 днів тому +1

    Amazing video! Thank you for sharing all of this valuable knowledge for free in such a well-thought-out and easy-to-understand format!

  • @jogydeep
    @jogydeep 10 днів тому

    Great video!! Hope to watch more about C with your explanation and visuals, you helped me to understand a lot of things I already assumed I wouldn't be able to get. Please keep going! 😊

  • @michaeldioguardi2180
    @michaeldioguardi2180 12 днів тому +8

    Thanks, Nic. I enjoy your content. I downloaded Clay for a project I'm working on. I hope to get it working soon. (Config is hard for me b/c I'm a noob) . Keep up the good work!

    • @nicbarkeragain
      @nicbarkeragain  12 днів тому +1

      Thank you, please drop by the discord if you're having problems and we can help you out 🙂

  • @testtest-qm7cj
    @testtest-qm7cj 11 днів тому +1

    Thank you for the fun introduction video. It brought me back to my memories of trying to learn C programming language for the first time. Personally, 23:59 is why I switched to C++ though. C++'s template syntax has its own pros and cons, but having a language-level support for generic programming with type information has been essential for my productivity, especially when it is paired with C++20 concept.

  • @GreeneThumbs
    @GreeneThumbs 5 днів тому

    I've been learning a little bit of C in my free time, this video is great

  • @dziuaftermidnight
    @dziuaftermidnight 11 днів тому +1

    @23:04 what you really wanna do here is pass "const Int32Array*" to the "get" function. there is no need for you to copy the array header upon invoking the getter function (and the reference to the array header can be const because you don't change it in the getter). if you do want to change it, then pass it as "Int32Array *", this way the change will be visible outside of the function (if you pass it by value, the change won't be visible on the original header data you have outside of the called function).

  • @janPolijan
    @janPolijan 11 днів тому

    I found your channel from your "clay" video and I'm happy I subscribed. This is an excellent video, especially for those not familiar with C or who have a negative opinion about it. It has all the right tips to make people realize programming in C can be effective... and happy.
    I'm a little torn on "Unity builds" because although they're a valid technique (except for when they occasionally lead to name collisions of static objects) for small-ish projets or to get your project off the ground, they require recompiling everything every time you modify anything. That can quickly become very cumbersome as the project grows. In the end, learning how to write (or adapt) a simple Makefile with auto-dependencies really is a time saver. Unity production builds could be useful for optimization. I'm not sure if it's still the case as modern compilers perform link-time optimizations (with `-flto` flag).

  • @wiseskeshom4673
    @wiseskeshom4673 11 днів тому +2

    Thank you so so much for your efforts. These tips are very useful for every C beginners.

  • @user-tw2kr6hg4r
    @user-tw2kr6hg4r 11 днів тому +4

    23:20 you cant just assume that the check is optimized out when not using a unity build. it is impossible for this check to be removed when when the getter is in a separate translation unit (without link time optimizations)

  • @francoisbechet
    @francoisbechet 11 днів тому

    Thank you so much, as a C developer this was so useful, especially that last part about arenas that should have been the first thing of the video!

  • @SeknaTS
    @SeknaTS 11 днів тому

    Great video Nic, thank you. Being in the handmade sphere, most of this is familiar to me by now, but I especially appreciated the discussion about the bounds checking and the array indexing, especially for serialisation. Although I was aware of each individual fact that was involved in coming to these conclusions, I had never put two and two together and considered that inlining the bounds checking would have the compiler optimise most or all of it away, and, even if it didn't, the CPU would mostly correctly predict the branching. Very fun to think about! I was also unaware of the compiler flags for address sanitisation. Thank you!

  • @acriliqueofc
    @acriliqueofc 11 днів тому

    The arena part was eye-opening. Thanks a lot for your videos man!

  • @TheDeathLimit
    @TheDeathLimit 11 днів тому +2

    This is pure gold ! THANK YOU !!!

  • @mkwise5996
    @mkwise5996 10 днів тому

    Thanks for this great video. Please create more videos like this to learn from beginner to advance level C programming.

  • @CorpoWolf
    @CorpoWolf 12 днів тому +1

    I remember slowly figuring out about the C things being conventions as I used it and the Unity builds.
    I wish your video existed when I first got into the language. You include so many details that would've been helpful very early on.

    • @nicbarkeragain
      @nicbarkeragain  12 днів тому

      I know exactly how you feel, I struggled through my first few years of C programming so I wanted to try to short circuit some of that pain for newer devs 🙂

  • @MyNameIsRache
    @MyNameIsRache 11 днів тому

    Thank you very much for this Video. I watched a lot of videos and "Tutorial" posts about C and I always was intrigued but also scared about doing "too" complex stuff in C. But with this Video and these general tips I already feel like it's a lot more approachable and fun to work with the language. I can't stress enough how much more likely these tips can find use than the 100th 12 hour introduction with no real life purpose.

  • @aliengarden
    @aliengarden 10 днів тому

    This video taught me a lot of things, great visuals, clear guidance, instant subscribe

  • @windwalkerrangerdm
    @windwalkerrangerdm 11 днів тому

    Did this just teach me the final stretch of c that I needed? YES I think so!

  • @Armitage1982
    @Armitage1982 11 днів тому

    This is a great source of information which answers a lot of the questions I've been asking myself about how to approach C these days when you come from a higher-level language like C#.
    I'm a bit bemused by the bounds checking solutions, but at least being aware of this concept allow me to look for the solution that suits me best.
    Arenas is also an interesting practice.
    Thank you for these important tips.

  • @fusca14tube
    @fusca14tube 11 днів тому

    Great video, amazing tips! Certainly, I'll watch again this content to learn more. In time, could you, please, make a video about debugging details? It's, for me, the most difficult stage of development in C! Thank you!!!!

  • @tommcboatface1908
    @tommcboatface1908 9 днів тому

    Fantastic video!!! Make a part 2!!!

  • @luyokai
    @luyokai 11 днів тому

    Thanks so much for your awesome video! It really helps me understand the foundamentals of the memory safety features in Rust and why they exist in the first place.

  • @nsteinhoff
    @nsteinhoff 11 днів тому

    Thanks for another great video!
    I've been chewing on the use of handles/indexes over pointers for a while now, and I think that it is a good recommendation in general. Combined with a data oriented / structure of arrays design, the indexes can become entity IDs that can be used to access the different component arrays. It also allows for generic algorithms and data structures. A hash table does not actually need to know the type of the data if all that it is returning is the index that the element should occupy in some external storage array.
    On the other hand, you lose type "safety". An index is effectively a void * that gets implicitly cast to the member type of any array that it is used to access. I think in Rust, (generational) indices are a way to side-step the borrow checker, because an index is not technically a reference. That's a cool trick, but, as with the pointer type, you are opting out of some feature of the language by doing that.
    Anyways, it's a great technique to have in the toolbox, and I would definitely watch a video that explores that idea in more depth 😉

  • @josiahjack455
    @josiahjack455 12 днів тому +10

    Fun obscure side note, QuakeC uses "Unity Build" where it compiles one file that just includes all the others (bit different but identical concept). And I can now thank you for giving this, my favorite build method, a name.

  • @PhotonCompute
    @PhotonCompute 11 днів тому

    Very useful. I also set C99 as the baseline standard but for a slightly different reason, with that being the level of compliance in implementations across compilers seeming to be consistently higher for C99 than for more recent standards.

  • @yash1152
    @yash1152 10 днів тому +1

    15:02 thanks for mentioning standalone debuggers. the gdb and clangdb are such a headache to use, & they make print debuuging look like a god sent saviour.

    • @yash1152
      @yash1152 10 днів тому

      i will look out for remedybg

  • @_mtmk
    @_mtmk 9 днів тому

    unity build is such a good option especially for people starting new or small projects, you don't want to get bogged down in learning how lovely cmake works but can focus on C itself. you can also compile a couple or few groups of files and link them in a simple 3-4 line script. such a relief!

  • @ahmedabdulmalik4792
    @ahmedabdulmalik4792 12 днів тому +1

    Man you are doing such great work helping us on YT and discord, thanks.

  • @MrPatrickbuit
    @MrPatrickbuit 2 дні тому

    It's the best language of all time imo. Complete control but the toolset you have is so simple. It's insane how well C ages.
    I might work in embedded.

  • @nezbrun872
    @nezbrun872 11 днів тому

    C89: you don’t have to declare all objects at the beginning of the function. You can declare them anywhere as a standalone statement,before their use. If you want to restrict scope within the function, simply start a new {…} block and declare them inside that block.
    But yes, C99 is a pretty good starting point.
    The beauty of C has been that the language itself is compact, and isn’t cluttered with syntax sugar like C++ or Python become.
    The issue of multiple header and source files is only a problem of you don’t have a plan and/or standard around it.
    However I would say that the preprocessor, while being powerful, does risk making read-only code.
    That “Unity Build” including multiple .c files is a solution looking for a problem, and frankly I wouldn’t hire someone who did that.
    Pointers are just something you pickup with experience, but yes, 40 years ago I didn’t know what I was doing either.
    Thank God K&R C was deprecated!

  • @cmr2079
    @cmr2079 11 днів тому

    I gave programming without header files a quick try today gcc. I works surprisingly well. One issue that I can see is that you'll have to be careful to manage the order things are declared, and how modules share globals and things between them. Headers could insulate you from some of these issues. I may just need to rethink how I organize things, though. Overall I think it's worth looking deeper into. I'm always looking for ways to simplify things.

  • @balazsmolnar5498
    @balazsmolnar5498 10 днів тому

    Thanks

  • @LuisFernando-wm5rg
    @LuisFernando-wm5rg 12 днів тому

    Last videos have been really good, hoping the algorithm reaches out more people 🙏🙏🙏

  • @moddeht
    @moddeht 4 дні тому +1

    This is an amazing video. Truly remarkable

  • @steffanomartinez1446
    @steffanomartinez1446 11 днів тому

    I got to learn the lesson of lifetimes, malloc & arenas in my first ever embedded dev internship for a medical robotics company. All I got to say is that learning this without the deadline and task completion pressure make's these topics and the language overall fun to look into (and easier) .

  • @tomsawyer3947
    @tomsawyer3947 11 днів тому

    Thank you for a very interesting and informative video! I've been programming in C since the early 90's and didn't know i was stuck in C89. I am such a Dinosaur!

  • @panos-onlyascii
    @panos-onlyascii 11 днів тому

    Lots of practical tips, well explained! Thank you for sharing!

  • @v84l42
    @v84l42 12 днів тому +1

    man this video makes me appreciate zig (programming language) a lot more.

  • @aaronmacdougall
    @aaronmacdougall 12 днів тому +1

    Great video. One minor note is that I don't think C89 can always be compiled as C++. Implicit void* conversions to other pointer types are not allowed in C++. It's a nice feature IMO, but to make them compatible you need to use a cast.

    • @leowolastname2250
      @leowolastname2250 11 днів тому

      technically possible to "bypass" (treat as a warning) using -fpermissive, but using -Werror would undo the "permissiveness" again

  • @violetsweet1660
    @violetsweet1660 11 днів тому

    I like C a lot more than I expected to, learning it after learning Rust. Part of what eased me into it was Paige Ruten's marvelous tutorial on how to build a text editor, step by step. Learning C forced me to develop a better mental model of computer memory. It also sometimes gives me insight into why Python works in certain ways lol.

  • @m4rt_
    @m4rt_ 6 днів тому +1

    I personally use the flags:
    -std=c11 -pedantic -Wall -Werror -Wextra
    I've also recently begun to use the -static linker flag.

  • @botteu
    @botteu 11 днів тому

    Great video, thanks ☺️ I’d like to see one about different compilers and why you would use one instead of the other (say gcc vs clang for example).

  • @aeyedeyen
    @aeyedeyen 12 днів тому +5

    I really enjoyed this video, but as someone who doesn't have much C experience, I was a little confused with the unity build portion. What is your strategy for when you need a file other than main to have access to another file? Does #pragma once work in c, or do you have to use #defile include guards all over the place? I would love to know your strategy for this more in depth as this is the most annoying part of using c/cpp in my opinion! Having a simple way to structure linking would be such a boon for making toy projects for practice when I venture away from the matronly arms of visual studio.

    • @Daniel_Zhu_a6f
      @Daniel_Zhu_a6f 12 днів тому +1

      unity builds are normally pretty simple. you have 1 main file, you include everything else in there, usually there are no headers at all (or a single header for all the code if it's a library). pragma once is supported by many compilers, but it's non-standard and ppl often use ifdef/endif. also ifdef/endif are the only way to make stb-style libraries (header, code and tests in a single file).

  • @RobertFletcherOBE
    @RobertFletcherOBE 12 днів тому +3

    Nice! I always love to c when you post a new video!

  • @myogeshm15
    @myogeshm15 11 днів тому

    great video, your explanation is very clean, the flow of the video is also great.

  • @alexdubkov6998
    @alexdubkov6998 3 дні тому

    Super video, interesting and useful. Thank you! Can you recommend relatively new books about Clang?

  • @mehtubbhai9709
    @mehtubbhai9709 6 днів тому

    @Nic Barker Undefined Behaviour in C and C++ is a nagging issue for me in the back of my mind. I'm always wondering, "Did I inadvertently introduce or overlook some UB somewhere."
    How do you deal with it?
    Super useful video as always👍

  • @Windeycastle
    @Windeycastle 10 днів тому

    Whoah, really good tricks, these will make me love C even more!

  • @christophemarois5423
    @christophemarois5423 11 днів тому +7

    You are unequivocally the most interesting teacher I've found on the web. I don't know what your goals are for this channel, but I'm now eagerly awaiting your videos!

    • @tomsawyer3947
      @tomsawyer3947 11 днів тому +1

      I had to look up the meaning of "pedagogue" so I was sure. Nic Barker is most definitely NOT a pedagogue. Calling him one seems very insulting to me.

    • @christophemarois5423
      @christophemarois5423 11 днів тому

      @@tomsawyer3947 Hey @tomsawyer3947. Thanks for correcting me. I'm a native french speaker, and "pédagogue" has... literally the opposite meaning as in English, which I wasn't aware of. Very sorry to have made this mistake, TIL. Edited my post.
      From Larousse Dictionary: Pédagogue: "2. Personne qui a les qualités d'un bon enseignant." - Person that has the qualities of a good teacher

    • @christophemarois5423
      @christophemarois5423 11 днів тому

      ​@@tomsawyer3947 Hey! Thanks for correcting me, this is very awkward. I'm a native french speaker, and you just made me find out that the word has... literally the opposite meaning in English. Very dangerous false friend word. TIL. Edited my post.

    • @christophemarois5423
      @christophemarois5423 11 днів тому

      Even Google Translate translates "pédagogue" (fr) to "pedagogue" (en), which is very, very wrong. From Larousse French dictionary: "Pédagogue: Personne qui a les qualités d'un bon enseignant." (person that has the qualities of a good teacher).

    • @tomsawyer3947
      @tomsawyer3947 11 днів тому +1

      @@christophemarois5423 We are BOTH learning a lot from this video and that's a VERY GOOD thing.

  • @52hands
    @52hands 11 днів тому

    Pure gold content, and you're a good presenter.

  • @schwoens
    @schwoens 9 днів тому

    Great video! Really easy to follow and very informative! I have to admit however, that it kind of convinced me to just use Zig instead, since it just has pretty much everything you mentioned built into the language haha.

  • @JamieBainbridge
    @JamieBainbridge 12 днів тому +12

    Good tips, especially to start using a debugger early. I also add -Wextra and -Wpedantic. C11 has Unicode literals and wide character types which become invaluable once you go past ASCII. If your program is not performance-limited then ship with sanitizers. For your array and string types, consider allocating the struct with the array member last and return the pointer to the array. The length data is still there but you can also just pass your array around like a normal array pointer. C11 also has generics. Your index should technically use size_t not i32, this would matter if you're storing byte indexes into a file larger than 2GiB.

    • @nicbarkeragain
      @nicbarkeragain  12 днів тому +5

      Yeah hiding the length before the array pointer in memory is such a cool trick, I believe it's how stb_array works 🙂
      I have definitely seen a few very tempting things in C11, another big one is thread local variables.

    • @JamieBainbridge
      @JamieBainbridge 12 днів тому +1

      @nicbarkeragain I also used to stick to C99 until a coworker suggested I should use the latest version possible unless I had a specific reason not to, thats when I changed to C17. I haven't looked into C23 in detail yet.

    • @julians.2597
      @julians.2597 12 днів тому +4

      You should also compile with -fno-strict-aliasing if you violate it for hiding a length.

  • @kentlarsson1263
    @kentlarsson1263 11 днів тому

    Very well produced and interesting! I might have to brush of any latent C skills (if any) from 17 years ago. In a world where most languages are exploding with new keywords, like JavaScript, it might be a refreshing experience.

  • @timwmillard
    @timwmillard 11 днів тому

    Awesome tips Nick. Loved the video.

  • @x-zotic_minded
    @x-zotic_minded 10 днів тому

    You don't see this typa comment but the graphical designs and their use is very on-point.

  • @leowolastname2250
    @leowolastname2250 11 днів тому +6

    I saw a comment saying you're basically reimplementing C++ and I partially agree. C++ does have many other language features outside of the standard library (templates, namespaces, classes, constexpr/consteval, lambdas, reflection(soon), etc.), but the (non null terminated) string struct, making bound checked getters, and using an IDE to autocomplete C++ function member syntax, did make the video very C++'y IMO.

  • @minecraftermad
    @minecraftermad 12 днів тому +3

    can't wait for C100

  • @OxAA00
    @OxAA00 День тому

    That's a great video! I'm mainly using zig but much of it translates actually quite well!