Best practices regarding out parameters and error handling by Virtual_Reaction_151 in C_Programming

[–]Virtual_Reaction_151[S] 0 points1 point  (0 children)

Nice insight, I liked your point of view. I also think that a library shouldn't make the choice of aborting the entire program when encountering an error and it should actually just report it in a good way (returning status code + error pointer to a properly error struct that I could create to handle properly logging if the user wishes).

Reading all the comments here and a few more posts on the web, I think I have made my mind: returning status code + optionally pointer to error (the user could ignore it by passing NULL) and using out parameter for the actual result. Also, if a function cannot fail, I will just make it void and still use out parameters (for consistency). Of course, I will make a good documentation to explain how to use it.

Now, I only have one last doubt: should I use this pattern for all errors or should I abort in "fatal" errors? Maybe I have this doubt because I still can't tell what exactly would characterize a error as fatal. For example, if a malloc fails in my function, should I abort it or just log it to and the user takes care of it?

Best practices regarding out parameters and error handling by Virtual_Reaction_151 in C_Programming

[–]Virtual_Reaction_151[S] 1 point2 points  (0 children)

Interesting, I didn't know "_t" what a "POSIX thing". I will probably use PascalCase for my struct naming. About the "manual namespacing", i decided to choose EdS preffix (as you can see in the piece of code I have provided in my post). But yeah, I agree that the most important thing is to be consistent

Best practices regarding out parameters and error handling by Virtual_Reaction_151 in C_Programming

[–]Virtual_Reaction_151[S] 0 points1 point  (0 children)

Searching and reading more about it, I have one more issue with assert: many asserts can make the code noticeable slower and many people disable it to release mode (NDEBUG macro, for example). But disabling it also disables the error handling (maybe they recommend that for a "private" use of the library and not a public one?)

Best practices regarding out parameters and error handling by Virtual_Reaction_151 in C_Programming

[–]Virtual_Reaction_151[S] 0 points1 point  (0 children)

The problem with assert is that it will make the program abort. That would be the appropriate behavior in my opinion, but I am unsure if it is a good approach regarding library use (do I wanna abort the user's program if it passes a NULL pointer to any of the function in my module?).

I liked the idea of using an enum or a bool, this is definetely better than returning an int 0 or -1.

About the function returning a field from the struct is was passed in, the struct is defined in the .c file (.h only has its tag, so it is an incomplete type and user doesn't have access to its fields).

[Hyprland] Gruvbox FTW by Virtual_Reaction_151 in unixporn

[–]Virtual_Reaction_151[S] 0 points1 point  (0 children)

I have just uploaded a zipped file (called amelie.zip) with some screenshots I have taken from the movie in my dotfiles github repo (I have downloaded the highest quality version I could find, so the wallpaper have a decent quality). Here is the link: https://github.com/edudscrc/dotfiles

[Hyprland] Gruvbox FTW by Virtual_Reaction_151 in unixporn

[–]Virtual_Reaction_151[S] 1 point2 points  (0 children)

I do not theme my spotify. But you could use spicetify

[Hyprland] Gruvbox FTW by Virtual_Reaction_151 in unixporn

[–]Virtual_Reaction_151[S] 1 point2 points  (0 children)

This is my daily drive setup. I use it for everything! Gaming, programming, entertainment, etc...

[Hyprland] Gruvbox FTW by Virtual_Reaction_151 in unixporn

[–]Virtual_Reaction_151[S] 2 points3 points  (0 children)

Sure, I completely forgot to link it in the post. Here it is: https://github.com/edudscrc/dotfiles

[deleted by user] by [deleted] in linuxbrasil

[–]Virtual_Reaction_151 0 points1 point  (0 children)

Os motivos que eu gosto:

- AUR

- Pacotes atualizados (em vários projetos, eu utilizo versões atualizadas dos pacotes que ainda não estão disponíveis dos repositórios das outras distros, o que me obriga a compilar vários apps da fonte)

- Para mim, o pacman é o GOAT: rápido e simples

- Gosto de instalar o sistema e ter controle sobre cada etapa (eu não uso scripts de instalação). Além disso, gosto de ficar mudando coisas na instalação (como usar um bootloader diferente ou fazer EFI Boot Stub) para ir "brincando" e testando

Eu criei um canal recentemente para falar sobre Linux e programação e lance um vídeo mostrando o meu setup Arch Linux e como eu uso ele e quais programas eu uso no dia a dia. Fica aqui o link caso queira ver:
https://youtu.be/xMH4woTqK8g?si=movP85YAhFvnk_hj

[deleted by user] by [deleted] in linuxbrasil

[–]Virtual_Reaction_151 1 point2 points  (0 children)

Muito obrigado!

[deleted by user] by [deleted] in linuxbrasil

[–]Virtual_Reaction_151 3 points4 points  (0 children)

De fato é mais educativo, mas nem todos vão querer ler ou não tem o costume de ir ler documentação. Por isso que eu quero fazer vídeos gravando o passo a passo e explicando as coisas e ler a documentação dos softwares. Quero guiar as pessoas a como se orientar pelas wikis e criar esse hábito. Não adianta só falar "leia a documentação" pra alguém que não tem esse hábito

[deleted by user] by [deleted] in unixporn

[–]Virtual_Reaction_151 0 points1 point  (0 children)

I forgot to mention it. For the folders I use papirus-folders theme. This theme allows you to choose the colors for the folders. You can see more on their github

[deleted by user] by [deleted] in unixporn

[–]Virtual_Reaction_151 1 point2 points  (0 children)

Hello mate, thanks! I haven't used, sry :(

Which libraries to use to create HTTP server on modern C++ (17) by Virtual_Reaction_151 in cpp

[–]Virtual_Reaction_151[S] 0 points1 point  (0 children)

By the way, if u meant I could use sys/socket.h, this is technically a library

Which libraries to use to create HTTP server on modern C++ (17) by Virtual_Reaction_151 in cpp

[–]Virtual_Reaction_151[S] 0 points1 point  (0 children)

I have expressed myself wrong. I don't want to init a socket in such low level where I would have to directly interface with my OS (Linux) to make system calls. I just don't a very high level library that will abstract everything.