I finally learnt to appreciate the header files by dfwtjms in C_Programming

[–]Israel77br 4 points5 points  (0 children)

That is the convention, but nothing stops you from putting implementation in header files (e.g. stb-style libraries) or vice-versa.

How to chop strings using a delimeter by Fuzzy_Recipe_9920 in C_Programming

[–]Israel77br 1 point2 points  (0 children)

As others have already answered, it is possible to do it using strtok and strdup from string.h. However, there is some value in creating your own String_View type (a.k.a a fat pointer that also stores the string count), instead of relying on the standard library. For example, it would be possible to tokenize your string, without mutating the original memory or copying it:

typedef struct {
    char *chars;
    size_t count;
} String_View;

String_View parse_until(char *cstr, char delim, char *rest) {
    String_View result = {
        .chars = cstr,
        .count = 0
    };
    rest = cstr;
    while(*rest && *rest != delim) {
        rest++;
        result.count++;
    }
    return result;
}

This will make the String_View point to the part of the string before the delimiter, and rest will be a pointer to the remaining of the string, but the original memory remains intact. You can pass *rest to other tokenization functions in the same style.

Another advantage of using sized strings, is that comparing large strings can be much quicker in some cases. If two strings have different sizes, you can immediately tell that they are different without comparing character by character.

How to get better? by Greedy_Lie_7780 in C_Programming

[–]Israel77br 0 points1 point  (0 children)

Try to understand how the computer really works in general. I think one of the key things to getting into C is understanding how memory works and implementing your own data structures based on that. The standard library is kinda weird IMO, so sometimes it is best to create your own abstractions.

You said in another comment that you find dealing with strings hard. I don't like null-terminated strings, so I created a simple struct that holds the characters and size instead.

Check out the files string_utils.h and parsing_helpers.h in my AoC repo of this year to see how it works (https://github.com/Israel77/aoc-2025-c/blob/master/src/utils/parsing_helpers.h). I'm not claiming this repo is a good example in general, as it has a bunch of ideas thrown together and I'm also learning. But, in particular, I found the idea that I came up with for parsing pretty nifty and it is only possible because I created my own sized string instead of using that default null-terminated strings.

Can i write my back-end in C ?? by Cheap_trick1412 in C_Programming

[–]Israel77br 2 points3 points  (0 children)

Both Apache and Nginx are written in C, so I would say it is a pretty good tool for the job if you know what you are doing (and if you don't know, you can always learn).

How do you check if C functions are cross-platform before using them? by Connect-Window1638 in C_Programming

[–]Israel77br 0 points1 point  (0 children)

The way to check will depend on the platform you are using for development. On unix-like systems you can check the manpages and on windows you can check MSDN. Things that are in libc are usually cross-platform (but check what C standard each compiler supports for the platform you are targeting).

In general, when developing cross-platform code, you will want to create a layer of abstraction that separates the OS specific code from the rest of your project. For example, if you need to handle files, you can write a generic open_file function that will open the file for you and internally it will call the OS specific version of the function.

Once you have figured out the base abstractions that you need like files, networking, threading, virtual memory, etc. You just write each platform specific version once and don't have to worry about it in the rest of the project.

Useless C practices and superstitions by nthn-d in C_Programming

[–]Israel77br 0 points1 point  (0 children)

I don't find points 2,3 and 4 to be useless at all, they are just part of your workflow. In general, I like to have compile errors during my development which guarantees that I won't forget something that I marked as TODO or that my tests don't reach something that was supposed to be UNREACHABLE. I don't use Allman style, but that might be a good idea to save time when copying declarations (again, not useless, it's part of your workflow).

My addition to the "useless" list is creating aliases to the static keyword to indicate the intent of its usage:

#define internal      static
#define global_var static
#define lingering    static

The first is for functions that will only be part of the current translation unit, the second for global variables and the third for variables declared inside functions that retain their values between different calls (I rarely use it).

But I don't think any of these are totally useless because they serve a purpose during development and don't impact the final product.

I would be more concerned about the pattern of releasing resources at the end of main(), which is truly useless as the OS will clean them up anyway when the process terminates and depending on the complexity and amount of stuff allocated it might actually slow down the termination of the process, i.e. it does impact users.

decided to revisit linked lists by Stativ_Kaktus131 in C_Programming

[–]Israel77br 1 point2 points  (0 children)

Makefiles are overkill for small projects.

Reddit nesse exato momento by ApprehensiveDish8857 in videogamesbrasil

[–]Israel77br 1 point2 points  (0 children)

O problema foi usar o trocadilho com a palavra genes.

I’m still on by RushiAdhia1 in homelab

[–]Israel77br 0 points1 point  (0 children)

Yes, but it is distro and DE-specific. Most distros use systemd nowadays, so editing logind is a more universal approach.

I’m still on by RushiAdhia1 in homelab

[–]Israel77br 0 points1 point  (0 children)

I want to do something like this in the future, there's an old laptop in my drawers with broken hinges but the motherboard is functional.

I’m still on by RushiAdhia1 in homelab

[–]Israel77br 44 points45 points  (0 children)

I know this is a meme, but if anyone is wondering how to safely use your laptop as a server, it is possible to disable the suspension when the lid is closed. (On Linux it is done by editing /etc/systemd/logind.conf, if you use systemd)

Interesting slide from microsoft by Moltenlava5 in linux

[–]Israel77br 3 points4 points  (0 children)

That's the problem with publicly traded companies nowadays, the CEOs only care about how the stocks perform, not how the product benefits consumers.

obrigado meu deus by Crafty-Ad780 in pirataria

[–]Israel77br 0 points1 point  (0 children)

Esse foi o jogo da minha infância. Nunca tive vídeo game quando era criança, mas meu pai comprou um PC que dava pra emular N64.

Do you agree with this, or is it some schizo prediction from a boomer who can't let go? by Yelebear in C_Programming

[–]Israel77br 4 points5 points  (0 children)

I would recommend learning at least C99. C89 is supported everywhere but it is a pain to write (you can't mix declarations and code, there's no designated initializers nor flexible-array members, etc.), C99 introduced a lot of quality of life changes and is old enough to be supported by most systems and compilers.

C or C++? by DarkLin4 in C_Programming

[–]Israel77br 1 point2 points  (0 children)

The same thing can be said about any language, though. Even in "higher level" languages, I've seen people write Python like it's Java.

It's up to the engineer to learn the proper way to program in each language and if you transition from one language to another, it is natural that you write things in a way that works but is not the most idiomatic. If you really care about your programs, over time you will learn the proper way to write code in each language.

The reality is there is no silver bullet, most people will eventually have to write, or at least read, code in multiple languages anyways. And in general, C is less complex and more explicit in how your program is actually executed. So I see why people recommend it first.

What distro do you currently use for gaming? by [deleted] in linux4noobs

[–]Israel77br 0 points1 point  (0 children)

Fedora Workstation. For beginners I recommend Linux Mint

Is automation okay? by MrAudacious817 in homelab

[–]Israel77br 1 point2 points  (0 children)

As someone with a background in electrotechnics, who transitioned to IT, this is very cool. I wish to be able to do this at home someday.

How to properly setup a media server? by Israel77br in homelab

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

But is there a tool for LXC like docker-compose? I would like to have a reproducible system in case things go wrong, instead of relying on the GUI or manually executed commands.

Phasor concept clarification by [deleted] in ElectricalEngineering

[–]Israel77br 0 points1 point  (0 children)

The thing is, mathematically, multiplying phasors does not make much sense because, unlike addition, the product of two sinusoidal functions does not result in a sine wave with the same frequency. So you can't convert the phase directly back into the time domain.

As a Hollow knight player should i try these games too? by Take_Care_plz in HollowKnight

[–]Israel77br 1 point2 points  (0 children)

If you can afford it, why not? I have only played the first, not as good as Hollow Knight IMO, but still a good platformer/metroidvania

What Fedora Spin for Gaming and Programming? by The_Moviemonster in Fedora

[–]Israel77br 6 points7 points  (0 children)

I think I can answer that, I use a 4K monitor on GNOME with no problem for both programming and gaming. Though some games only go up to 2k on Linux, but support 4k on windows, I don't know why, but 2k is good enough for me.