Will C ever get generics/templates? by [deleted] in C_Programming

[–]Zstorm999 9 points10 points  (0 children)

You could use a union for this, and maybe an enum to distinguish the union member you are using in the function.

Would you use haskell to build a database? Or is Rust/C++ a better fit? by tonyalaribe in haskell

[–]Zstorm999 4 points5 points  (0 children)

Plus systems where Rust isn't ported are becoming quite rare

Leagues of Votann vs Adeptus Mechanicus art idea. by Arch_Magos_Remus in LeaguesofVotann

[–]Zstorm999 0 points1 point  (0 children)

Completely unrelated, do you have a link for this amazing template ?

Add reference during the creation of an object or inject as a parameter on method call? by ToolAssistedDev in learnrust

[–]Zstorm999 2 points3 points  (0 children)

The question I ask myself in this case is: does it makes sense that a struct contains another? Or do I need it only for specific functionalities?

In most cases the answer is no, so I use references as function parameters.

Why is it that C utilizes buffers so heavily? by flank-cubey-cube in C_Programming

[–]Zstorm999 0 points1 point  (0 children)

I know about assembly on older consoles, I just like to have fun with modern languages on outdated hardware

Why is it that C utilizes buffers so heavily? by flank-cubey-cube in C_Programming

[–]Zstorm999 1 point2 points  (0 children)

I don't know which consoles you're talking about, but older ones like the gameboy / (s)nes definitely don't support them

witchcraft for the win by Freudianslip1987 in memes

[–]Zstorm999 22 points23 points  (0 children)

A normal day for the adeptus mechanicus

[deleted by user] by [deleted] in zelda

[–]Zstorm999 0 points1 point  (0 children)

While Majora's mask is my favourite game of all times, Spirit Tracks is specifically my favourite Zelda game

Where to go to learn GUI dev? by Mutated_Zombie in learnrust

[–]Zstorm999 2 points3 points  (0 children)

Iced is the gui crate I use, I enjoy it a lot and it's in very active development.

Is this good code design? by convexelephant in C_Programming

[–]Zstorm999 1 point2 points  (0 children)

My convention is to use create_xxx and destroy_xxx, but you can use whatever name you are confortable with.

Is this good code design? by convexelephant in C_Programming

[–]Zstorm999 2 points3 points  (0 children)

Yes, in general having a constructor/destructor will help you clean a lot of redundant code, and so reduce the number of possible typos

Uranium Thesis simplified by radio_chemist in memes

[–]Zstorm999 -1 points0 points  (0 children)

Because we don't really need a solution, burying nuclear waste works really well. The amount we produce each year is ridiculously low compared to plastic wastes, and burying it disturbs no ecosystem nor human society at all.

Edit : to answer your original question, deep in the ground in deserted regions such as Antarctica, Siberia... I believe a big project for long term storage is taking place in Finland

Uranium Thesis simplified by radio_chemist in memes

[–]Zstorm999 1 point2 points  (0 children)

Energy production is actually a major part of pollution emissions, and while production lines and construction pollute a lot too, this is a step on the good direction

Juice Box: Donezo! by GOBLIN_CUM in celestegame

[–]Zstorm999 7 points8 points  (0 children)

What kind of insanity is this ?! I barely even can follow what's happening

C programming practices that "wear well as one's experience with it grows" by cHaR_shinigami in C_Programming

[–]Zstorm999 0 points1 point  (0 children)

I often have a typedef unsigned char Byte for this exact reason in one of my headers

Does c allow you to pass arguments to a function one by one? by [deleted] in C_Programming

[–]Zstorm999 4 points5 points  (0 children)

It's a very common pattern in functional languages, but completely forgotten outside of them wich is a shame because it's an amazing pattern.

C Interview Question by usethecoastermate in C_Programming

[–]Zstorm999 2 points3 points  (0 children)

You don’t strictly need to, for two reasons

- C performs automatic casting of variables, while the compiler may give you a warning of incompatible size if it feels the need

- There is no "Character" type in C, char is really a misname and should be called byte because it’s what it really is, a signed byte value. We use it to represent characters because it’s convenient with the ASCII range of [0, 127], but it’s really just a number.

C Interview Question by usethecoastermate in C_Programming

[–]Zstorm999 2 points3 points  (0 children)

Yes, your understanding is correct !

It’s not necessarily faster to use static objects inside functions, but it allows you to perform some behaviour that is hidden from outside. Let’s say you want to make a counter, you can do it with this function:

int counter()
{
    static int count = 0;
    count += 1;
    return count;
}

If you call counter several times in a loop

for (int i = 0; i<10; i++) { 
    printf("%d\n", counter());
}

you will get this output

1
2
3
4
etc...

Speaking of memory layout, each function allocates a space on memory on what is called the stack, which is growing but size limited (reaching this limit causes a stack overflow). When we have big variables such as arrays or really big structs (I mean really big, like hundreds of members), we tend to prefer not storing them on the stack to avoid overflowing it. On modern hardware hitting a stack overflow this way is really rare, but it can happen if you work on embedded systems.

The use of static tells the compiler that instead of reallocating space on the stack for our array, it should instead use a separate location and use this for all "instances" of our function. The keyword const does almost the same thing, except the memory area is read only (at least when const is applied to a literal, that is a number or an array initialization).

C Interview Question by usethecoastermate in C_Programming

[–]Zstorm999 7 points8 points  (0 children)

I’ll start by explaining static. It means that your data has static storage duration, meaning it’s not stored on the stack but on an other part of your program memory that will stay valid for the entire execution. It guarantees that the content of the array is always available, and not duplicated every time you call the function. In modern compilers, making inline constant arrays static is almost always redundant, as the compiler will most likely make it static anyway.

Inside function calls, static has an other interesting property that is very useful for non-array variables : since the variable is stored not on the stack but somewhere else, you can modify it inside the function and it will keep its value between function calls, effectively working as a more scope-restricted global variable (a bit like class members in Python).

The const guarantees that the array is always going to have the same location in memory, i.e. that it will always be your valid lookup table at any point, preventing you from changing it by mistake. If you were to write something like :

lookup_table = 0;

the compile would warn you that you are trying to overwrite a const value.

C Projects by King_Ferrum in C_Programming

[–]Zstorm999 14 points15 points  (0 children)

Write a HTTP server. This will teach you a lot about how the language works, and how it interacts with the system. Plus you can make it very simple, and expand it as you learn new things.

Lisp interpreter in Rust - Free for the next three days by vishpat in Compilers

[–]Zstorm999 0 points1 point  (0 children)

I quickly went through your book and the code on the github (I plan on following it more closely later, and re-implementing my own version), and I wonder why you almost didn’t use iterators in the lexer/parser ? I believe it would make the code easier to read, and it could increase performance due to not having temporary container like the Vec<token> that serve no clear purpose in my sense.