r/C_Programming
Reading assembly of a C source code directly inside neovim
Give me suggestions to understand c programming in the first semester?
I am facing difficulties learning C programming. Currently, I don't have a laptop, so I can't practice that way. I'm unable to understand even the basic topics of C programing currently. Please give me some tips on how to improve.
Edit: Understood. I can actually learn it through practice on a laptop; I'll get a laptop soon.
I’m learning C and made a simple version of ls. Could someone review my code?
I’m currently learning C and decided to build a simple version of ls as a small project to practice what I’ve learned.It’s still pretty basic, and I’m sure I’ve made some mistakes or done some things in a bad way. I’d really appreciate it if someone could take a look at the code and point out any bugs, bad practices, or things I could improve. Repo
Help me with strok function
I need to split my string but if it is of char* type the functions strtok() doesn’t work returning me a segmentation fault. I understood that C is used to lock the memory of the string in Read-Only “mode” when I use char*. Does it means that is immutable that data? However, I need to use the char* type because I pass that in a function (and I don’t like to use the syntax of arrays in C, I always use pointers).
The first time I understood why i++ and ++i aren't always the same
When I first started learning C, I thought i++ and ++i were basically interchangeable because both increase the value of i by 1.
Then I saw them being used inside expressions and realized that the difference is actually about when the value is used versus when it is incremented.
That was one of those small C concepts that looked obvious until I actually had to predict the output of a program.
Now whenever I see ++i or i++, I pay attention to what happens to the value before and after the expression is evaluated.
VScode C file only running in terminal
I just started learning C on my own and I am currently needing help running C files on VScode, the problem I am having is that the C file can only be run on terminal, when i try to run it in Debugging it shows some kind of error and stuffs, when i try to run it in output the pop up appears that says "Code Language not supported or defined", I have every necessary extensions and path and everything set up, I had try pretty much everything I can think of and it is still not working.
MONOLITH - My Operating System for the x86/x86_64
Introducing MONOLITH, my operating system that I worked on for the past two years, supports both x86 and x86_64, privilege separation, preemptive multitasking, SMP, loading user processes, a desktop environment running in user space, and most importantly it can run Doom!
Feel free to check it!
Minimizing output size
I've looked at stackoverflow answers from 10 years ago (https://irq5.io/2019/09/30/generating-small-static-binaries/ , https://stackoverflow.com/questions/33597523/why-is-smallest-compiled-exe-i-can-make-with-gcc-is-67kb/76705747#76705747 , https://stackoverflow.com/questions/6771905/how-to-decrease-the-size-of-generated-binaries , https://stackoverflow.com/questions/15314581/g-compiler-flag-to-minimize-binary-size , etc).
In all of the links on top, people were able to get sub-KB file sizes. However, no matter how much I copy and try their code, I cannot get any less then 8-9KB without assembly and upx.
Is there a reason these hacks do not work anymore?
I am on x86_64 Linux-7.2.8, gcc is 16.2.1.
Example:
$ cat t.c
#include <sys/syscall.h>
#include <unistd.h>
void _start() { syscall(SYS_exit, 0); }
$ gcc -Os -nostartfiles -static -s -Wl,--build-id=none t.c && strip a.out
$ l a.out
-rwxr-xr-x 1 name name 8.8K Oct 6 20:25 a.out
# The same code produced only 800 B in https://irq5.io/2019/09/30/generating-small-static-binaries/
The first time I understood that a pointer doesn't store the value — it stores where the value lives
When I first learned pointers in C, I kept thinking of a pointer as another variable that somehow contained the value of another variable.
The concept finally clicked when I stopped thinking about the value itself and started thinking about the memory address where that value is stored.
Once I understood the relationship between & (address-of) and * (dereferencing), pointers became much less mysterious.
I'm still practicing pointers, but this was one of those concepts where a small change in perspective made everything easier.
Communication Between the Compiler, the Build System, and Beyond
An article I wrote about how sharing dependency and resource information between the Compiler, the build system, the system package manager, and even the OS filesystem and scheduler, could provide some pretty interesting benefits. I’d love to hear anyone’s thoughts on this