How to do error handling in C and get specific error in a human readable form. Social links: Website: cacharle.xyz Github: github.com/cacharle Linkedin: / charles-cabergs-328aa8214
Пікірлер: 44
@darrenfernandes41895 ай бұрын
great video but I thought it would be c# XD
@grimvian3 ай бұрын
At last, finally someone makes great advanced C videos, fantastic! And big thanks for not having disturbing background music and irrelevant graphics editing. Your pedagogical skills are also great, because you have the editor and the console side by side and the pace is fine and not having irrelevant info included on the screen. What about making a video or more about sending outputs to a default printer? Of course you got a new subscriber.
@cacharle3 ай бұрын
Thank you for the kind words :) Having as little distractions as possible is my trade mark and it will keep being that way. Unfortunately I have never written code to interact with a printer and I don't have a printer at home so I can't help you with that (I wouldn't be surprised if you can find a clean cli tool or a library to interact with printers tho)
@grimvian3 ай бұрын
@@cacharle I have now discovered a library cops.h and understand, that is widely used in Linux. I can use Raylib.h and print ttf characters and lines on a virtual graphical page and then via cups make a hardcopy to the printer. And this little code can also print although I'm new to Linux and do not yet understand the command. #include #include #include int main() { char text[] = "Hello, Printer! "; char command[256]; sprintf(command, "echo \"%s\" | lp -d $(lpstat -d | cut -d' ' -f4)", text); if (system(command) == -1) { perror("Failed to print"); return 1; } printf("Text printed successfully! "); return 0; } I admit it's not my code. :o)
@SeanCodingThingsАй бұрын
A good next video on Advanced C might be how to take user input from a user safely in a loop in a "clean" way. It's harder then it might sound.
@cacharle27 күн бұрын
Indeed, I could make a video on `getline`, a very useful function. Or one where I detail the *get* functions and warn about buffer overflows with `gets`. Thank you for your suggestion.
@SeanCodingThings25 күн бұрын
@@cacharle 👍
@starc0w5 ай бұрын
Super useful! Thank you so much! Really great stuff 🙂
@cacharle5 ай бұрын
I'm glad you're enjoying this series :D
@MegaPacoquinha21 күн бұрын
Do you recommend any advanced books on c++ or c, on fat pointers, dynamic dispatching and other complicated stuff?
@cacharle21 күн бұрын
I very rarely read books about programming. I read The Practice of Programming by Rob Pike but it's not really advanced or focused on C if I remember correctly. I have rewritten malloc as a side project and I would like to make a video about it some day (malloc uses fat pointers) and I have touched on dynamic dispatch in my video about "lookup tables" where I show my sed project: kzbin.info/www/bejne/l3a8npRogreGfrM
@youdontknowme25085 ай бұрын
Great video as always
@cacharle5 ай бұрын
Thanks! :D
@spacewad87455 ай бұрын
fine video but man the gruvbox colorscheme is so timeless. looking forward to your work!
@cacharle5 ай бұрын
Thanks, I like the comfy vibe of the gruvbox theme, makes me feel at home 😅
@davidreilly6578Ай бұрын
Great video man keep up the good work 😊
@cacharleАй бұрын
Thank you :D
@goncaloazevedo98225 ай бұрын
Would love a video on varargs!
@cacharle5 ай бұрын
Already made one: kzbin.info/www/bejne/i2nWpIimoteKsKs And for macro variable argument aswell: kzbin.info/www/bejne/hZSxfWNthraCjKs
@goncaloazevedo98225 ай бұрын
@@cacharle Amazing brother 🙌
@SeanCodingThingsАй бұрын
Nice!
@oschonrock5 ай бұрын
very good.... maybe also show the "goto" pattern for free'ing resourcs in case of error.
@cacharle5 ай бұрын
Ye, I was planning on doing that but I've never used it myself, I just know it exists and how it works.. so I feel less qualified to talk about it
@oschonrock5 ай бұрын
Well thx whole resource free'inf in the context of errors is quite tricky to get tight IMO. Multiple techniques exist just show the one you use?
@cacharle5 ай бұрын
I use the dumb and easy way: r1 = f1(); if (r1 == NULL) return NULL; r2 = f2(); if (r2 == NULL) { free(r1); return NULL; } r3 = f3(); if (r3 == NULL) { free(r1); free(r2); return NULL; } I can see why someone would want to remove the duplicate free's, but tbh, I very rarely encounter a case where I have more than 2/3 resources in one function so this simple technique is fine for my needs.
@oschonrock5 ай бұрын
Yeah that's fair. I think it's still worth a video to explain that.
@cacharle5 ай бұрын
Indeed, I'll think about it.. Any other resource management technique I should know about other than the dumb one and the goto one? I think I saw some people make a `defer` macro but I'm not sure if it was in C++ or C.. EDIT: it was in C++ www.gingerbill.org/article/2015/08/19/defer-in-cpp/ :'(
@rednibcoding34123 ай бұрын
Great series, thank you! I am a software engineer for about two decades, but always used managed languages like C#, Java etc. Now i have to learn c and delve deeper into low level programming. I know the basics but i am so used to having dynamic arrays, lists, maps, even a proper string data type and all that stuff. Sometimes i have a hard time with this. When i look on YT about C tutorials, they all start at zero for total beginners. What i need is a complete tutorial for programmers switching to C. What are the best practices when you need dynamic arrays or lists or maps. Will one write them themselves? If yes, could you show it to us? What are the best practices about memory management? What allocators are suited best for what needs, how do they work, and how do you implement them? Could you make such series? That would be really awesome!
@cacharle3 ай бұрын
Hi, I just made a video about writing your own dynamic array in C (and I also played around making it a "generic" data structure on stream). I am planning on doing more videos like this in the future. I think the main advice I have for someone that comes from a higher level programming language is try to just use the basic C features *as much as possible*. You will be very surprised by how many times it is possible to replace a dynamic array by a fixed size array, a map with an enum and a "lookup table", a string by a char array. Do not try to shoehorn these high level constructs in C. If you really need them, you can either rewrite them yourself or there is probably libraries that do that for you aswell (altho I've never felt the need to use one)
@grimvian3 ай бұрын
I'm a hobby programmer and I am at the finale of an little application for my wife's business, a relations database in C, Raylib graphics for user interface and Linux Mint. I'm using CodeBlocks and the debugger is very good to tell you where your logic fails. Because I really want learn C, I decided to build my my own string handling for editing. It's a enormous satisfaction, when your own library does the handling correct and gives lots cries, when it's not.
@cacharle3 ай бұрын
@@grimvian I also started writing C using CodeBlocks :D it is pretty good to learn but it started to get in my way when I wanted to do more advanced stuff from what I remember (ofc don't change editors if you're comfortable with it) The C standard library already has a lot of string handling functions which are very useful. Depending on your usecase, it might be necessary to implement a more dynamic string data structure like C++ or Python (which is basically just a dynamic array of characters). If I was you, I would really try to keep it simple at first and only use the standard library and regular character arrays.
@grimvian3 ай бұрын
@@cacharleI' very bad at typing and reading, so I'll have to stick with CodeBlocks and I'm a hobby coder most of the time. I do not think for a second I'll do better string handling than the standard library, it's just because my own library keeps me on my toes. I also used it for the editing in my database for my wife's business, although it was quite a task have the data on the disk and string handling and the graphics in place, but it seems to work fine now or else I'll know very quickly, because of my wife :o). Even insert and overwrite and a timed cursor, that correspond to ins/overwrite are in place. So it's great that someone like you is making advanced C videos and I think many C learners have tried many of the beginner videos and want to go on. I saw that a advanced C course costed about 3000 euros in Denmark, where I live...
@PLAYGAME-wj9bw5 ай бұрын
Super vidéo mais ça aurait été bien de mentionner goto 👍
@cacharle5 ай бұрын
Je sais, quelqu'un me l'a dit dans un autre commentaire mais je n'utilise pas cette methode personnelement
@leonardopisano95754 ай бұрын
En français, S.V.P. 😂
@cacharle3 ай бұрын
jamais! 😄
@basilenordmann7356Ай бұрын
Hum… réécrire des fonctions, un accent français… 42?
@cacharleАй бұрын
Oui, j'ai fait l'ecole 19 a Bruxelles 😅
@basilenordmann7356Ай бұрын
@@cacharle haha démasqué! 😜 C’était bien à Bruxelles ? C’est recommandable ?
@cacharleАй бұрын
@@basilenordmann7356 Oui c'etait tres bien. Apres je suis jamais aller visiter d'autre ecole dans le Network 42 donc je peux pas vraiment comparer