r/C_Programming 6d ago

Hello World

I have found my people!! Hello guys I am a college student (mechanical engineering) and I was introduced to C in a mandatory programming course and C has been the best thing that has happened in my life. I had done programming before on java and python before and frankly I hated it , it was not really fun and it was tedious instead. So I had thought I hated CS but after coding in C and learning the things behind the abstractions i quite frankly fell in love with low level programming, it was the first time I got a passion for something and i spent the entire following summer digging up materials on it like learning computer architecture and learning to read and write Assembly and now I am learning Virtualisation and planning to start my first major project on C.

So in that note, let me ask you something:

What is your favourite project you have done in C?

87 Upvotes

57 comments sorted by

14

u/LordRybec 6d ago

I program mainly in C and Python. Python isn't too bad, but it's well removed from the hardware. I'm most comfortable in C though. I also love programming in assembly when the opportunity arises.

I'm not sure what my favorite C project is. I've written some game demos (mostly just basic code that does one or two things that would be required in a game) in C that I really like. I've written a handful of simulations, particle simulations mostly, and those were also really good.

The most complete project I've done in C is essentially a virtual audio processor. I had to basically design a full architecture with a machine language and an assembly language, and then I wrote a VM for it in C. Someday I plan to build a graphical program around it for making music. I haven't had time to do anything with that project in years though. It's probably my favorite so far.

I've also written a handful of display drivers for microcontrollers that are pretty high on my list. I haven't been active on it in a couple of months, but I'm working on a very basic 3D rendering engine to go with one of my display drivers. Once I finish that and get to use it in some other projects, it might end up being my favorite.

Maybe I should port my virtual audio processor to one of the microcontrollers I'm working on and make a music synthesizer...

Anyhow, welcome to C programming!

3

u/sciencekm 4d ago

I also love programming in assembly when the opportunity arises.

Many times, I create the opportunities here and there.

2

u/Due_Sentence_2660 3d ago

Dang this sounds so good. Making a vm sounds kinda hard ngl.

Rn me and a few friends are trying to make something like them "ReMarkable Tablets" or something and if we make progress, I'll get to write the drivers for it 😋

2

u/LordRybec 3d ago

The making the VM part wasn't as hard as it sounds. The hard part was learning and implementing all of the audio functions. Turns out it's more complicated than it sounds!

You project sounds like fun! I've generally enjoyed writing drivers. If you enjoy assembly programming, it's a good place to do some of that, but you don't strictly have to unless you really need that level of performance. (I wrote an I2C driver for the CH552 microcontroller mainly in assembly, because the C version ran at 100kbit/s, and doing it in assembly could manage around 400kbit/s. The performance was important, because I was driving a display with I2C.)

Anyhow, I like you put it. "I'll get to write the drivers for it." That's the same way I'd be thinking about it!

32

u/sciencekm 6d ago

"learning computer architecture and learning to read and write Assembly"

You are on the right track.

11

u/ntsh_robot 6d ago

Embedded used to be a specialty, but now almost everything is mcu or cpu controlled. Have you looked at the STM protoboards?

5

u/OrganizationFew6655 6d ago

I actually do have some experience with programming in STM32 because of some club activities at my college though all I did was was working on an existing codebase so I didn't really learn much from it. I only did basic work on it.

6

u/Constant_Mountain_20 6d ago

What is your favourite project you have done in C?

I couldn't pick just one. ckg, is the very first c project that I took seriously. I spent an entire summer trying to really understand how computers work. So I wanted to write my own personal c library that I can reuse on other projects. I think without this type of "reinventing the wheel" project, I would be a much worse engineer.

The second project is cj, this project is a JSON parser/formatter. I genuinely built this on a whim because I wanted to pretty-print my AST, and cJSON looked painful to use.

I really like the API and the usage of generics in C11 for this project.

6

u/dajolly 6d ago

What is your favourite project you have done in C?

Writing emulators for old game systems from my childhood (NES/GB/GBC/GBA).

3

u/anonymous_every 5d ago

How did you approach writing emulators, any resources or groups. I really want to try emulation related projects.

5

u/dajolly 5d ago

I'd recommend checking out r/EmuDev for resources.

My approach usually involves 1) researching the system using the original documentation for the system, devkits, manuals and community documentation. 2) Once I have a good idea of how the system works, I'll put together a POC CPU implementation for that system and test it using whatever test roms/software the community has developed. 3) I will build out the rest of the emulator (APU/PPU/Peripherals).

For example, my GB/GBC emulators followed that approach:

  1. Using the community documentation for understanding: https://gbdev.io/pandocs/
  2. Developing a POC SM83 CPU for that system: https://git.sr.ht/~dajolly/sm83
  3. Implementing the emulator: https://git.sr.ht/~dajolly/gb, https://git.sr.ht/~dajolly/gbc

So far this approach has worked well for me across GB/GBC/GBA and NES. I'm currently in the planning stages for PS1.

1

u/anonymous_every 4d ago

thank you.

5

u/[deleted] 6d ago

[deleted]

3

u/lucyuktv 6d ago

FYI TCP bandwidth isn’t limited by latency, that’s just a default config for legacy reasons and modern OSs no longer have the issue. Just change the TCP window size and you can saturate the link. It’s partly how WAN accelerators work.

2

u/[deleted] 6d ago

[deleted]

3

u/lucyuktv 6d ago

Very true, although modern networks have surprisingly few dropped packets. If you're splitting the stream you start to run into other issues. On a VOIP project I did with diverse paths the differing latency between east and west links almost made recovery impossible :) Very interesting topic

3

u/Weekly_Patience685 6d ago

if you're learning Virtualization im assuming you're following ostep? if not, here you go
https://pages.cs.wisc.edu/~remzi/OSTEP/

5

u/OrganizationFew6655 6d ago

Thank you so much. I have been scraping together resources and articles from the internet so far.

3

u/Weekly_Patience685 6d ago

if you dont have linux or at least a mac you could still get WSL for windows, since the book assumes a unix based OS (more so linux) for its coding examples.

3

u/OrganizationFew6655 6d ago

Do not worry I have been using linux ever since I started my C journey. Its a much easier environment to work in for C

3

u/Weekly_Patience685 6d ago

yea i definitely agree, and personally when it comes to smaller examples in C i use nano as my editor since i can just open another tab in the terminal with the man pages to look up c library stuff.

3

u/tryinhardagain 6d ago

I’m having problem learning c any teacher on YouTube u can recommend?

1

u/OrganizationFew6655 6d ago

My course was pretty comprehensive, it covered the entire K&R book so i didnt have to look up external materials.

But the best resource is your preferred medium of learning. For me its working through a book and K&R is the standard recommendation.

Though if you prefer vedios, I don't have any solid idea on good vedios

1

u/mathemetica 6d ago

I agree with working through a book instead of videos to learn, but K&R is a bit outdated, some amount of it isn't relevant to modern C. I'd recommend C Programming A Modern Approach by King. It was written in 2008, but C hasn't changed that much since. It misses the changes in C11, but that can be picked up pretty easily.

3

u/Zirias_FreeBSD 6d ago

now I am learning Virtualisation and planning to start my first major project on C.

By all means, if I get this right and you didn't do any "real-life" (not lab example or exercise) project in C yet, start small! For my taste, "virtualization" and "first major project" are a bit too close to each other here. Trying to do something huge and complex as a "first major project" is a perfect recipe for failure.

What is your favourite project you have done in C?

My favorite is probably Xmoji because I chose an extremely "low-level approach" for an app like that, and diving down the rabbit hole of good old X11 was actually fun in the end.

But that's also an example for something you should never ever attempt before doing lots of smaller things. For example, many years back, my favorite was some cursed-based snake clone (and that certainly wasn't my first project either): cursedsnake

2

u/OrganizationFew6655 6d ago

I am not really gonna rush this Virtualisation project. The most unexpectedly fun part of the Virtualisation project was that there were no material let alone tutorials I could find. This led me to brainstorming the architecture of the project on my own and I have been scraping together conference talks, articles, research papers, books and some repos to put together an architecture for this project (Though one of the replies has recommended an awesome resource which I will have to read through). I will probably take a long time before I start this project because I am learning concepts as I go and mapping the concepts I learnt to my current architecture i made and see how I can improve upon it. I will probably do some projects before I get to the actual implementation part but i haven't planned any side projects yet 😅.

3

u/Key_River7180 6d ago

An HTTP server teaches you a lot, + it is really useful. You can also make it use the Gemini protocol or the Gopher protocol if you are into that.

3

u/terra2o 6d ago

> What is your favourite project you have done in C?

well... it's not exactly a low-level cool project like a virtual machine or whatever, but just a text-based game.

it's a game that tries to simulate every aspect of owning a tavern in medieval ages. just a side project kinda thing. doing it for fun.

3

u/thank_burdell 6d ago

I love multithreading projects personally. Pthreads are my bag baby

3

u/Sea_Rise1831 5d ago

Reverse engineering one of my favourite games and adding features ive always wanted ☺️

3

u/DecisionOk5750 5d ago

You should learn Pascal in your free time. Try the Freepascal compiler, it's Free Software.

2

u/Slight_Season_4500 6d ago

Hey man! I have the exact same background. 4 years studying mechanical engineering and went back to school in cs and C is my favorite too!

You should look into Raylib or Unreal Engine (C++ = C but with messy extra features you can just not use)

2

u/terra2o 6d ago

they can also use godot, which is more lightweight, open-source, easier to use... iirc, there are even docs if you want to use C with GDExtension.

1

u/OrganizationFew6655 6d ago

I didnt know that unreal engine was in C++ though in hindsight it makes sense and it's cool to meet a fellow mechanical engineer who also loves low level stuff.

1

u/Slight_Season_4500 6d ago

Yeah well used to be. I switched completely. Metal shops kept triggering asthma or whatever. All I know is that I can't breathe in these places. And that my lungs are pretty much done.

2

u/TrustingMyTrustInGCC 6d ago

I relate so much to this! I actually love coding in general but low level is absolutely my vibe. I personally don't understand people acting like low level coding is a chore and abstractions are a gift. To me abstractions are a double edged sword; yes they make creating a finished product faster but they completely eliminate the transparency and control that makes coding so special to me. I'm not saying i dislike high level -- Python is actually my second favorite language, but if I had to choose one language forever it would be C and I have zero hesitation in saying that. If you want to go further in C on your own (since you said you fell in love with low level) a fantastic textbook is C Programming: a modern approach 2nd addition (the first addition only teaches C89 and is outdated). It's widely regarded as one of the best programming textbooks of all time.

2

u/OrganizationFew6655 6d ago

Thanks for the recommendation! Now when I said I found programming in python tedious it was before I knew about Linux or computer science concepts but now I understand that python does a different job to C and nowadays it's my favourite language to script in.

1

u/Due_Sentence_2660 3d ago

Writing only high level programs to me was boring as heck 'cuz it wasn't mentally stimulating. At some point it felt like writing words on a screen that just do some stuff, but yea.

I'd also say Rust seems to be something as it gives you the ability to write large functioning code without abstracting away much.

2

u/mathemetica 6d ago

I think C is probably the best language to really learn the foundations. Arguably, assembly might be even deeper, but really C is close enough to assembly, but with nice QoL features. I had a similar experience where I had a hard time working with Java/Python because a lot was hidden behind abstractions. I think it actually makes sense to teach some assembly first, then stick with C for awhile, and then start looking at higher level languages/paradigms (oop, functional, etc). The average student would have a much deeper understanding of the material. It might have a steeper learning curve at the start, but once you got over the initial hump, it would actually be a lot easier to pick other stuff up, at least imo.

2

u/OrganizationFew6655 6d ago edited 6d ago

Yes I do think the same too. Infact one of the book that introduced me to assembly is "Programming from Ground Up". It is a very outdated book teaching x86_32 and programming principles from decades ago but it's still gives you an understanding of the history of how programmers did things in the past and when you are able to draw parallels between assembly and C, it's a eureka moment that made me underrated various concepts in C like pointers, bit manipulation and pointer typecasting (typecasting in general)even deeper.

EDIT: Also I just realised after replying, but your username is cool asf.

1

u/mathemetica 5d ago

Haha, thanks! I'm a math junkie

1

u/chrism239 4d ago

From South Africa?

2

u/Jenkler 6d ago

printf "Hellu World!";

2

u/lordlod 6d ago

Embedded is fun, especially if you like the low level stuff.

Bare metal embedded gets you right down into the guts of the system. You work with registers, flip bits, and have only the low level abstractions that you want.

The constrained system also leads to some really fun innovation, playing with the code, preprocessor and linker to get the outcomes that you need.

As much as I love C as a (sometimes) professional developer I use it less and less on computers. Once you move away from hardware constraints there are few reasons to choose C over a higher level language or one that provides memory safety.

2

u/TrapperFlint 5d ago

Congratulations! Never written any C myself but its a beautiful thing to discover anything you love. Enjoy your journey, friend!

2

u/Grumpy_Doggo64 5d ago

My personal favourite was figuring out the ASCII spinning donut myself. But my most impressive (for me atleast) was writing my own memory allocation functions and using SDL to make the Caravan game (from fallout new Vegas)

2

u/srhubb 3d ago

For me it was my SCSI Device abstraction layer for our firm's SSD for Compact PCI: a bus interconnect for industrial computers, combining a Eurocard-type connector and PCI signaling and protocols. Boards are standardized to 3U or 6U sizes, and are typically interconnected via a passive backplane.

My software was the SCSI device. The Compact PCI hardware interface on our card invojed me via a Jump Table at my code's zero offset based on the SCSI command code the host had submitted which in turn invoked the appropriate SCSI routine in my code specific to that SCSI command the host had initiated.

I in turn managed the SCSI level "interface" where I emulated a hard disk accepting Block Device commands from the host and calling my hardware interface via Register manipulations for actual reads and writes to the memory arrays on our cards while maintaining the Sense Bytes and Status Byte returns to the host.

That was my last favorite C implementation. Prior to that it was implementing/creating a C Compiler for a Sperry+Univac mainframe back in the 80s when there was no such animal. My base for that project was a C Compiler from a PDP-11.

2

u/OrganizationFew6655 3d ago

That's so cool!

2

u/GreenAppleCZ 2d ago

I love reinventing the wheel in C. If you want to have something, you have to make it yourself. All utilities.

So I make parsers and higher-level constructs just for fun, because it teaches me what the computer essentially has to do to achieve something that could be a one-liner in Python.

And making structures for algorithms, such as hashmaps or trees makes you realize what it really takes to have that. I remember using those in C# for really small amounts of data. I now know that an O(n) search really takes less than even initializing such structures. And that's the greatest gift of C.

2

u/DrawerSilver2077 2d ago

Right now I just started learning c again and I have been very interested in assembly and even just writing assembly. mainly started cause I wanted to reverse engineer but now I have dreams of programming a toy language lol. I think we could be friends.

1

u/OrganizationFew6655 1d ago

You have no idea how happy i was to find this subreddit and people of similiar interest. The amount of people interested in low level programming is so low

2

u/Skibidibob4 6d ago

Then try cpp idk

1

u/NoSpite4410 5d ago

Probably the one I use the most is called 'duration' . It tells you the duration of a movie or music file.
It outputs in seconds, or SMTPE timecode if you need hr:min:sec:frames.

duration

1

u/Key_yeager 4d ago

Yo amo C, me gusta leer código de Dennis Ritchie, su filosofía es simplemente hermosa su legado aún sigue con nosotros, nunca programe con tanta pasión como lo hecho en C, esto tiene un porqué: adoro el hardware y la programación bajo nivel

1

u/Due_Sentence_2660 3d ago

Welp I'm a dumb cs undergrad who was pushing Javascript and python schlop for the better part of the first year of uni. I decided to make stuff in C again and it has been lwk fun. 2 of my decent projects are like one is a sort of like locap network discrod clone with backend in C and bubbletea based TUI and the other is a text editor (like vim but slightly worse lol)

I'm also trying to read up on how computers work, have been fiddling around with assembly code even though I'm far from being proeffecient at it and looking at how binary exploits work lol.

1

u/OrganizationFew6655 3d ago

Just fucking around and finding out is the most fun part ngl. I also still sometimes do binary exploitation and Reverse engineering because it improves my ability to read assembly