[icon ] blenderdumbass . org [icon scene] Articles

C Programming Language is an Interesting Experience

August 04, 2026

👁 6

https://blenderdumbass.org/do_login : 👁 1

#c #programming #clang #gcc #python #c++

License:
Creative Commons Attribution Share-Alike

[avatar]by Blender Dumbass

Aka: J.Y. Amihud. A Jewish by blood, multifaceted artist with experience in film-making, visual effects, programming, game development, music and more. A philosopher at heart. An activist for freedom and privacy. Anti-Paternalist. A user of Libre Software. Speaking at least 3 human languages. The writer and director of the 2023 film "Moria's Race" and the lead developer of it's game sequel "Dani's Race".


11 Minute Read



I just wrote a functional program in C. It is not doing anything too fancy. But I'm so happy about it because of what it means. For the longest time I didn't know pretty much nothing except of Python. I can use Python for a lot of very interesting stuff. But I want to be able to look at code written in different languages and know what I'm looking at. I want to be able to make changes to the UPBGE game engine for my game Dani's Race and stuff. ↩ Reply

I know, I know, UPBGE is a fork of Blender and therefor is written in C++, not C. What am I wasting my time, learning C, for? Well... ↩ Reply

If C++ is a fork of C, with extensions on top of what C can do. I should understand the difference between the two, I suppose. And therefor I should, first of all, have some idea of what it is like to program in C. ↩ Reply

Here is a surprising thing about this whole endevour. I started looking into C today. And already while writing my first program journal, which I will be talking more in depth about in this article, I already felt like I know the language enough to solve little annoyances and overall code rather quickly in it. It felt almost like writing python code. ↩ Reply

C has modules, kind of like python. In python you import modules using import. Say you want to have access to the operating system functions. You can write something like this: ↩ Reply

import os




And it will give you the whole os modules to do things with in the operating system. ↩ Reply

In C you #include them instead. ↩ Reply

#include <stdio.h>




This stdio.h file is a C code file ( as far as I understand ) that exists somewhere relative to the compiler. And the code of that file is injected into your code. So it is a bit different in practice. ↩ Reply

In python to call a function from os I would be formatting it like this os.getcwd() or something. In C all the functions in the files you include are dumped straight into the same context as everything else. ↩ Reply

For example stdio.h has a function called printf() useful to print stuff into the terminal. It is not stdio.printf() or anything stupid like that. You are just simply using printf() directly. ↩ Reply

I imagine what a pain in the ass this must be for large projects. You have to keep track of so many names. And not, by mistake, define a function with a name that already exist somewhere, in some library you want to use for some task. ↩ Reply

Another strange thing about C is that you must have a main() function where the main execution thing of your code is done. ↩ Reply

In python you just type away. A "hello world" program in python is very simple: ↩ Reply

print("hello world")



In C print does not exist and you have to define a main() function. So in C a "hello world" program is a bit more complicated: c:0 ↩ Reply

#include <stdio.h>
int main() {
    printf("hello world\n");
}




Funny, I wrote this example rather fast for this article. I'm still rather shocked how quickly I'm getting to the point where I can use C for things. And I did double-check myself. This code compiles and outputs an identical output to the python code above. ↩ Reply

Now you can spot a few differences of approach. First the inclusion of the \n thingie in the C version. printf unlike python's print doesn't end every line with a new-line character. You have to specifically tell it to do so. Then there is the ; after each operation. This is because C is indentation agnostic. In python the white-space stuff, like indentation and new line characters, are used to separate stuff, not just visually, but functionally. In C you have visible marks that separate code. Like the ; sign after every operation. I needed time to get used to this. ↩ Reply

Variables are simple but not simple. In python you have so many types of data. You have int for integers and float and floating point numbers and str for text and list and dict and tuple and other various interesting, useful things. In C you have almost none of it. ↩ Reply

You've got your int and float and stuff. And you've got stuff like char which represents a single character of text. ↩ Reply

Now you can do something like this: ↩ Reply

char text[256];




which will be similar to doing something like: ↩ Reply

text = ""



in python, But notice a few things. First you have to specify that it is a char type. Then you can do many char at once, kind of like a list in python, to store some characters-long strings of text. But you have to specify how many of those characters long, this object is. I think in the real world it literally allocates 256 bytes of RAM ( in this example ) for my text string. And running out of this space might cause all sorts of issues. ↩ Reply

Also comparing strings isn't simple either. ↩ Reply

When I was playing around with the language I wanted to make a simple if statement. I input some text and if the text I input is one thing, I do one thing, and if it is something else I do another thing. ↩ Reply

I tried doing this: ↩ Reply

if ( text1 == text2 ){ dosomething(); }



But even though it never errored out, it never worked either. ↩ Reply

Apparently I must do this instead: ↩ Reply

#include <string.h>
if ( strcmp(text1, text2) == 0 ){ dosomething(); }
c:1


The string.h file has the strcmp() function I can use to compare texts. And if the texts are the same, it will return 0. So I need to compare the output of this function to 0. It is a bit annoying. ↩ Reply

In any-case, I decided to write something useful. Writing something useful is always a good stepping stone into learning a language. ↩ Reply

Just a few days ago I wrote a simple GTK program in Python to keep track of my weight. It basically records data I drop at it into a JSON and then shows it to me in a way that makes sense to the task. ↩ Reply

So I thought, okay... how hard would it be to read and write a JSON in C? Ah... I found this. And the size of this whole thing made me feel wrong. And then I found another something to do with C and JSON and the way they described doing it made me feel un-easy. ↩ Reply

See, because C doesn't have a dict like python, making a JSON like structure of data inside of a C program becomes a pain in a butt. ↩ Reply

I decided, fuck it. What is the simplest shit I can do? Well maybe something like a journal writing program. Every entry is a line in a .txt file. All you need to do to present it, is just to printf the whole file. And it is probably doable. ↩ Reply

I present to you journal.c ↩ Reply

#include <stdio.h>
#include <string.h>



int help() {

  printf("\n\n");
  printf("          HELP DIALOGUE of JOURNAL\n");
  printf("\n");
  printf("    help - Print this helps message.\n");
  printf("    save - Saves a text into the journal.\n");
  printf("    show - Prints out the entire journal.\n");
  printf("\n\n");
    

}

int save(char string[]) {

  FILE *data;
  data = fopen("journal.txt", "a");
  fprintf(data, "\n%s", string);
  fclose(data);


}
int show() {

  FILE *data;
  data = fopen("journal.txt", "r");
  char string[1024];

  printf("\n\n");
  
  while( fgets(string, 1024, data) ){
    printf("%s", string);
  }
  
  printf("\n\n");

}

int main(int argc, char *argv[]) {

  if (argc == 1 || strcmp(argv[1], "help") == 0) {
    help();
  }
  else if (argc == 3 && strcmp(argv[1], "save") == 0) {
    save(argv[2]);
  }
  else if (argc > 1 && strcmp(argv[1], "show") == 0) {
    show();
  }


}



You can save it as journal.c and run this command: ↩ Reply

gcc journal.c -o journal



to compile it into an executable. ↩ Reply

And then ↩ Reply

./journal help



to see the help of this program. ↩ Reply

Yes this program does system arguments. And you know what. Those are simple. ↩ Reply

int main(int argc, char *argv[]) {



This line defines the main() function, but look what it also does, it gives it arguments. What? System arguments are built-in in C? ↩ Reply

The argc variable contains the amount of arguments and the argv is a list of lists of characters. A list of text strings. A list of the arguments themselves. ↩ Reply

So from that point it becomes kind of simple. If there are no arguments or the second argument is help ( because the first one is the name of the program ./journal ) we run the help() function. Or in code: ↩ Reply

if (argc == 1 || strcmp(argv[1], "help") == 0) {
    help();
  }




And if you look into the help() function. It is just a bunch of printf(). ↩ Reply

Then if the argument is show we open the file and dump its content into the terminal. Now that is not quite as simple as you think. ↩ Reply

The fun part was to realize that fopen() is like either built-in or a part of the other stuff I already imported. So opening and saving files is actually not that big of a problem in C. ↩ Reply

But the code to dump a file into a terminal is strange: ↩ Reply

  FILE *data;
  data = fopen("journal.txt", "r");
  char string[1024];

  printf("\n\n");
  
  while( fgets(string, 1024, data) ){
    printf("%s", string);
  }
  
  printf("\n\n");



There is a FILE datatype apparently. Python has something similar. Not unlike python's read() C has fgets(). But because the string you are saving to has a certain pre-specified buffer size ( in the case of this code 1024 bytes ), you are reading the file one chunk at a time. And as I have noticed, one line at a time too. ↩ Reply

So while in python it would look like this: ↩ Reply

print("\n\n")

data = open("journal.txt", "r")
print(data.read())

print("\n\n")



in C we need to do a while loop and read the data until there isn't any. Which is a bit weird. ↩ Reply

Also you can't printf() a string directly. You need to append it like that printf("%s", string). What? ↩ Reply

On top of that it seems like C doesn't have much error handling at all. I can open a nonexistent file. And it will just have zero bytes in it. Instead in python it will error out. ↩ Reply

So yeah. It was fun. I know enough C to write pointless bullshit in it now. And to, hopefully, understand more complex code written in it. ↩ Reply

My next challenge. C++. Let's do it. Let's go! ↩ Reply

Happy Hacking!!! ↩ Reply

[icon unlike] 4
[icon right]
[icon terminal]
[icon markdown]

Find this post on Mastodon

[avatar]  Troler c:0 August 04, 2026


In C print does not exist and you have to define a main() function. So in C a "hello world" program is a bit more complicated:
⤴ View

And... your code is going to segfault, you did not provide a return statement.

... replies ( 1 )
[avatar]  Blender Dumbass c:2 August 04, 2026



@Troler I compiled it and tried it and it worked. So apparently it is not that needed.




[icon reply]
[avatar]  Troler c:1 August 04, 2026


if ( strcmp(text1, text2) == 0 ){ dosomething(); }
⤴ View

I would write the code as

if ( !strcmp(text1, text2) ){ dosomething(); }



This is more in style of C, that is, less readable.

... replies ( 1 )
[avatar]  Blender Dumbass c:3 August 04, 2026



@Troler lol




[icon reply]
[avatar]  Blender Dumbass c:2 August 04, 2026


... c:0
[avatar]  Troler c:0 August 04, 2026


In C print does not exist and you have to define a main() function. So in C a "hello world" program is a bit more complicated:
⤴ View

And... your code is going to segfault, you did not provide a return statement.


@Troler I compiled it and tried it and it worked. So apparently it is not that needed.

... replies ( 1 )
[avatar]  Troler c:4 August 04, 2026



@blenderdumbass That's because the compiler adds it for you. main() is an int function, it requires to return an whole number. Here, the number represents the return code.




[icon reply]
[avatar]  Blender Dumbass c:3 August 04, 2026


... c:1
[avatar]  Troler c:1 August 04, 2026


if ( strcmp(text1, text2) == 0 ){ dosomething(); }
⤴ View

I would write the code as

if ( !strcmp(text1, text2) ){ dosomething(); }



This is more in style of C, that is, less readable.


@Troler lol

[icon reply]
[avatar]  Troler c:4 August 04, 2026


... c:2
[avatar]  Blender Dumbass c:2 August 04, 2026


c:0

@Troler I compiled it and tried it and it worked. So apparently it is not that needed.


@blenderdumbass That's because the compiler adds it for you. main() is an int function, it requires to return an whole number. Here, the number represents the return code.

... replies ( 1 )
[avatar]  Blender Dumbass c:6 August 04, 2026



@Troler Well I'm greatfull the GCC isn't stupid.




[icon reply]
[avatar]  Robert Kist 🇦🇹🇩🇪 c:5


@blenderdumbass the nice thing about both C and Python are that they are nice, concise languages, that yet have a great amount of depth. Now C++, well, there's also all that sprawl...

[icon reply]
[avatar]  Blender Dumbass c:6 August 04, 2026


... c:4
[avatar]  Troler c:4 August 04, 2026


c:2

@blenderdumbass That's because the compiler adds it for you. main() is an int function, it requires to return an whole number. Here, the number represents the return code.


@Troler Well I'm greatfull the GCC isn't stupid.

[icon reply]
[icon question]











[icon articles]C Programming Language is an Interesting Experience

[thumbnail]

[avatar]  Blender Dumbass

👁 6 ❤ 4 🔄 1 💬 7



I just wrote a functional program in C. It is not doing anything too fancy. But I'm so happy about it because of what it means. For the longest time I didn't know pretty much nothing except of Python. I can use Python for a lot of very interesting stuff. But I want to be able to look at code written in different languages and know what I'm looking at. I want to be able to make changes to the UPBGE game engine for my game Dani's Race and stuff.


I know, I know, UPBGE is a fork of Blender and therefor is written in C++, not C. What am I wasting my time, learning C, for? Well...


#c #programming #clang #gcc #python #c++


[icon articles]How to Make a Blog Like Mine Using BDServer Software?

[thumbnail]

[avatar]  Blender Dumbass

👁 104 💬 1



I want to document the way you might have a possibility to use the same software to make a similar website. @Madiator2011 already done that with blog.madiator.com. Lets go over: where you get the code, how do you set it up, how do you publish, how do you manage accounts, and most importantly, how do you modify everything, so it will look like your own thing.


#blog #blogging #webdev #website #python #programming #BDServer


[icon articles]The Structure of Dani's Race Codebase ( July 10th 2026 )

[thumbnail]

[avatar]  Blender Dumbass

👁 9 ❤ 2 🔄 1 💬 1



This is less of an article and more of an overview into how Dani's Race ( a game I'm developing ) works. Note, there is a date in the title of this article. Anything here is subject to change. But I don't think a lot of it will be that different in the end of the day.



#danisrace #moriasrace #game #gamedev #freesoftware #blender3d #python #programming #hacking


[icon articles]Please Help Me With Activity Pub

[thumbnail]

[avatar]  Blender Dumbass

👁 101



This article is published on a website which is powered by BDServer. And I'm trying to make this website support ActivityPub, so you could for example, subscribe to me from your Mastodon account. Yet it is easier said than done.

If you have any experience with ActivityPub, web-development or Python, please consider helping me. We have BDServer Matrix Chatroom.


#activitypub #fediverse #mastodon #bdserver #python #programming #webdev #federation #API


[icon articles]UPBGE - What is Depsgraph? And How to Optimize for Depsgraph?

[thumbnail]

[avatar]  Blender Dumbass

👁 215



You see things like "Physics", "Logic" and even "Rasterizer" and you immediately understand what you need to do to optimize you game. But "Depsgraph"?... It looks like a mysterious thing that nobody knows nothing about. Yet is it one the most problematic things there is in your game. And you are going mad just trying to figure it out.



#DanisRace #MoriasRace #Game #Gamedev #UPBGE #blender3d #animation #GTAClone #programming #python #project #performance #depsgraph


[icon articles]Winning Dani's Race ScoreBoard on WINdows

[thumbnail]

[avatar]  Troler

👁 39 💬 6



I want to get the scoreboard working on Dani's race, but I'm using Winblows operating system. That means a lot of things are broken. That's because Dani's race was developed for the Tux operating system.


#danisrace #moriasrace #game #gamedev #freesoftware #blender3d #python #windows #leaderboard #programming #hacking


[icon codeberg] Powered with BDServer [icon python] Plugins [icon theme] Themes [icon analytics] Analytics [icon email] Contact [icon mastodon] Mastodon
[icon unlock]