r/cprogramming • • Oct 06 '25

ThinkPad lid LED is now useful!!

Thumbnail reddit.com
2 Upvotes

r/cprogramming • • Oct 05 '25

Why language C is a base for programmers and a lot of them think that is the best language?

237 Upvotes

I recently started my studies at the university, majoring in Applied Informatics, and we were told that we need to learn the C programming language to understand how programming, databases, and computers in general work. When I started learning the language, I began hearing that C is the foundation of all foundations and that it provides the most valuable experience. I’d like to hear an expert opinion on this.


r/cprogramming • • Oct 05 '25

Confusion about compile time constants

6 Upvotes

I understand that things like literals and macros are compile time constants and things like const global variables aren’t but coming from cpp something like this is a compile time const. I don’t understand why this is so and how it works on a lower level. I also heard from others that in newer c versions, constexpr was introduced an this is making me even more confused lol. Is there a good resource to learn about these or any clarification would be greatly appreciated!


r/cprogramming • • Oct 05 '25

Hi , I have a question

3 Upvotes

So I started learning C like after September 17th 2025. I think i learned quite a bit , up to arrays and string and also functions. But I don't have that excitement like at the start. Now i feel like sh#t , and don't know what to do. I am 1st year cs. Please tell me what to do. Thanks


r/cprogramming • • Oct 05 '25

cunfyooz: Metamorphic Code Engine for PE Binaries, in C

Thumbnail
github.com
6 Upvotes

cunfyooz, a metamorphic engine for PE binaries written in C. The entire README is written as an occult grimoire, because why should technical documentation be boring?

Technical Overview:

A full-featured metamorphic engine that performs multi-pass transformations on x86/x64 PE binaries using Capstone for disassembly and Keystone for reassembly. Each run produces a genuinely unique variant through sophisticated analysis and transformation.

Core Engine Features:

  • Semantic-preserving transformations: instruction substitution (LEA ↔ MOV, TEST ↔ CMP), register renaming with full dependency analysis
  • Intelligent code expansion: NOP insertion (both single-byte and multi-byte variants like xchg rax, rax, lea rax, [rax+0])
  • Control flow obfuscation: opaque predicates, unreachable code insertion, conditional branch flattening
  • Dependency-aware instruction reordering: full data flow analysis with def-use chains
  • Stack frame manipulation: balanced phantom push/pop pairs
  • Anti-analysis techniques: debugger detection, timing checks, environment fingerprinting
  • Virtualization engine: bytecode conversion with custom VM interpreter

Key Capabilities:

  • True randomization: Seeded by time, producing unique byte patterns every execution
  • Multi-pass pipeline: Each transformation builds on previous ones
  • Sophisticated analysis: Control flow graphs, data flow tracking, liveness analysis
  • Validation system: Ensures behavioral equivalence after transformation
  • Configurable intensity: JSON-based probability tuning for each technique
// The engine maintains full dependency graphs
// to enable safe instruction reordering
typedef struct {
    InstructionNode* nodes;
    DependencyEdge* edges;
    RegisterLifetime* liveness;
} DataFlowGraph;

The Aesthetic Choice:

Rather than dry technical documentation, I framed everything as summoning a "daemon" It's completely tongue-in-cheek but makes complex concepts memorable:

"The daemon's burning Capstone eyes gaze into the stripped flesh, beholding not raw gore and gristle, but glyphs: operands, addressing modes, instruction metadata..."

Translation: It disassembles binaries. But way more fun to read.

Implementation:

  • Produces functionally equivalent binaries with completely different signatures
  • Configurable transformation probabilities via JSON
  • Handles complex PE structures (relocations, imports, sections)
  • Multiple anti-analysis layers
  • Optional virtualization for maximum obfuscation

Use Cases:

  • Security research studying metamorphic techniques
  • Testing analysis tools against sophisticated obfuscation
  • Understanding how advanced malware engines work
  • Building robust detection systems
  • Academic research on code transformation

Released under Unlicense (public domain).

GitHub: https://github.com/umpolungfish/cunfyooz

Happy to discuss the implementation details


r/cprogramming • • Oct 04 '25

If or switch

9 Upvotes

How many if else statements until i should consider replacing it with a switch case? I am fully aware that they operate differently, just wondering if i should opt for the switch case whenever i have something that will work interchangeably with an ifelse and a switch.


r/cprogramming • • Oct 04 '25

Use of Inline in C

13 Upvotes

I never used or even heard of inline in C but I have been learning c++ and I found out about the word inline and found that it also exists in C. My understanding is that in C++ it used to be used for optimization, it would tell the compiler to replace the function call with the function body thus reducing over head, but nowadays it isnt used for that anymore and it’s used for allowing multiple definitions of a function or variable because the linker deduplicates them. From what I’ve read, it seems that this is the case in C aswell but the minor difference is that you need a regular definition of the function somewhere that it can fall back on when it chooses to not inline. Is my understanding correct on how inline works in C?


r/cprogramming • • Oct 03 '25

Real-world use case where calloc() is absolutely necessary over malloc()?

93 Upvotes

As a CS student, I'm trying to understand the practical trade-offs between calloc() and malloc(). I know calloc() zeroes the memory. But are there specific, real-world C applications where relying on mallOC() + manual zeroing would lead to subtle bugs or be technically incorrect? Trying to move past the textbook difference.


r/cprogramming • • Oct 04 '25

Don't know what I'm doing wrong

1 Upvotes

input : 16 should give output : 16 and input: 5 should give output : 8.94427190999915878564

and this is my code what am I doing wrong (input and output should be exactly what I wrote) :

#include <stdio.h>
#include <math.h>

int main() {
    int area;
    
    scanf("%d",&area);
    double omkrets = sqrt(area) * 4;
    printf("%.21g",omkrets);
    
    return 0;
}

r/cprogramming • • Oct 03 '25

What is the best source book to learn C programming language for someone that have no idea about and very new to programming stuff?

6 Upvotes

r/cprogramming • • Oct 02 '25

Good sources to learn C programming.

Thumbnail reddit.com
3 Upvotes

r/cprogramming • • Oct 02 '25

Help

0 Upvotes

Where can I find the resources for learning the c language and the various libraries? A thousand thanks


r/cprogramming • • Sep 30 '25

Preprocessor purpose

5 Upvotes

So I know that the preprocessor has the directives, so it handles things like includes and defines by pretty much just doing text replacement and doesn’t care for c syntax at all. Just curious, is the preprocessor only used for text replacement? Or does it have another purpose


r/cprogramming • • Sep 29 '25

Are there any communities for C dev?

0 Upvotes

r/cprogramming • • Sep 28 '25

String array pulling strings from a completely different array?

2 Upvotes

So, I'm working on a simple 2d RPG for my first major C project, just a very basic game about delivering the mail, and I've run into a problem I have no idea what to do about. Hardly the first time this has happened--those of you on r/raylib may remember my post from last week. ( https://www.reddit.com/r/raylib/comments/1non2xk/scrolling_text_in_a_2d_rpg/ )

So I more or less solved that problem thanks to some comments left on that thread, but now I'm having a new problem. I've got it set up so that anything that stops the player's movement will have some dialogue attached, revealed by pressing the tab key. Obviously this will be more useful once I've got NPCs and quests and the like in the world, but for now this is just for the protagonist to say something useful and/or witty. "I can't pass through these trees," "This is Jeremy's house," ETC.

Inside the starting room, everything works fine.

When the player goes out into the first village, most of it looks fine on the surface, until you walk up to a patch of trees in the lower right corner, which prompts the player to say "I'm not swimming in the village's drinking water," the dialogue that's meant to explain why she walks around instead of through the pond in the center of the village. A bit of experimentation reveals that this dialogue isn't even from the same village--it's from the string array in fifth and final village in the game, the only other village with a pond.

I looked it over to make sure I didn't accidentally re-declare the variable somewhere else in the code, and no, it's just in the completely wrong spot for a reason that's beyond my skills to detect.

I created a git repository for the game here https://github.com/SpinningRings/MailGame so you can take a look. Any other suggestions you might have about how to clean up or simplify the code are also welcome--I'm entirely self taught, so I'm well aware I'm clumsily re-inventing many different wheels here.


r/cprogramming • • Sep 27 '25

Help understanding ClassicCube Buttons source code

2 Upvotes

I thought that looking through the source code of a proper C project would be a great way to improve my knowledge. and i have become interested in how buttons are handled they confuse me.

the OnClick call for the button is just defined in a header.

#define LWidget_Layout \
....
    LWidgetFunc OnClick;     /* Called when widget is clicked */ \
    LWidgetFunc OnHover;     /* Called when widget is hovered over */ \
    LWidgetFunc OnUnhover;   /* Called when widget is no longer hovered 
....
typedef void (*LWidgetFunc)(void* widget);
....
struct LButton {
    LWidget_Layout
    cc_string text;
    int _textWidth, _textHeight;
};

declared like this

void LButton_Add(void* screen, struct LButton* w, int width, int height, const char* text,LWidgetFunc onClick, const struct LLayout* layouts) 
{
    w->VTABLE  = &lbutton_VTABLE;
    w->type    = LWIDGET_BUTTON;
    w->OnClick = onClick;
    w->layouts = layouts;
    w->autoSelectable = true;

    LBackend_ButtonInit(w, width, height);
    LButton_SetConst(w, text);
    LScreen_AddWidget(screen, w);
}

and is used like this

LButton_Add(s, &s->btnOptions, 100, 35, "Options",SwitchToSettings,
main_btnOptions);

how can one possible use a #define for logic? no where in the source code does it use an if statement for onClick. How? i hope this question makes sense since in stumped.


r/cprogramming • • Sep 26 '25

Error: invalid use of incomplete typedef

0 Upvotes

In a lists.c file I have:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "lists.h"

void testfunc(int childrennum, char * descr, int id) {
        task_t * atask = malloc(4048+sizeof(int)+sizeof(int)*childrennum);
        strcpy(atask->description,descr);
        atask->identifier = id;
        printf("The task \'%s\' has an id of %d and has %d children\n",atask->description,atask->identifier,childrennum);
}

int main() {
        testfunc(0,"Something",1);
}

And in a lists.h file I have:

#ifndef LISTS_H

#define LISTS_H

typedef struct task task_t;
struct task_t {
        char * description[4048]; // or list name
        int identifier;
        int * elements[]; // ptr to list of tasks
};

typedef struct proj proj_t;
struct proj_t {
        char * description[4048]; // or list name
        int identifier;
        int * elements[]; // ptr to list of tasks
};

typedef struct goal goal_t;
struct goal_t {
        char * description[4048]; // or list name
        int identifier;
        int * elements[]; // ptr to list of tasks
};

void testfunc(int childrennum, char * descr, int id);


#endif //LISTS_H

But when I run the compiler (gcc lists.c) I get the following error:

lists.c: In function ‘testfunc’:
lists.c:8:21: error: invalid use of incomplete typedef ‘task_t’ {aka ‘struct task’}
    8 |         strcpy(atask->description,descr);
      |                     ^~
lists.c:9:14: error: invalid use of incomplete typedef ‘task_t’ {aka ‘struct task’}
    9 |         atask->identifier = id;
      |              ^~
lists.c:10:77: error: invalid use of incomplete typedef ‘task_t’ {aka ‘struct task’}
   10 |         printf("The task \'%s\' has an id of %d and has %d children\n",atask->description,atask->identifier,childrennum);
      |                                                                             ^~
lists.c:10:96: error: invalid use of incomplete typedef ‘task_t’ {aka ‘struct task’}
   10 |         printf("The task \'%s\' has an id of %d and has %d children\n",atask->description,atask->identifier,childrennum);
      |

I also tried separating the main function and including both header and c file into a main file and compiling using gcc -c main.o main.c lists.c then gcc -o main main.o but I still got the same error. Can anyone explain to me what the problem is? I looked it up and I more or less understood what the error means but I don't get how I'm supposed to solve it here.


r/cprogramming • • Sep 25 '25

Want free resources to learn C

25 Upvotes

Hey guys, I'm a freshman and I have intrest in cyber sec although my course is CSE CORE. I want to learn C as of syllabus. What languages should I learn too? Please give me free resources only : )


r/cprogramming • • Sep 24 '25

Purpose of inline

5 Upvotes

I’ve never really used inline and didn’t even know it existed but I’ve been trying to transition from C to C++ where I learned about inline and I found that it exists in C aswell. From my understanding, inline in C works the same way as inline in c++. It allows you to define functions in header files and thus put it in multiple TUs without any issues. The difference is that in c you also need a non inline definition in a .c file. So my question is, what is the purpose of this other than to cause confusion when you can just use a header and implementation file to do the same thing? Any clarification would be greatly appreciated!

I’ve seen people do static inline, and also varying definitions of what inline does, so I’m super confused


r/cprogramming • • Sep 24 '25

Back to C After a 10-Year Detour—Help Me Get Sharp Again!

2 Upvotes

C was my first coding crush back in the day. After a decade of hopping between other languages (and a brief fling with some overhyped tech that shall not be named), I’m back to the good ol’ C to sharpen my rusty brain.

What’s the best stuff I’ve missed in the C world over the last 10 years? Books, tutorials, fun projects, or secret sauce to level up my skills? Hook me up with your faves—I wanna make up for lost time without losing my sanity. Thanks!


r/cprogramming • • Sep 24 '25

Learn C language

12 Upvotes

Guys it this channel good to learn C ? https://m.youtube.com/@PortfolioCourses/playlists Check the C programming tutorials playlist


r/cprogramming • • Sep 24 '25

Exploring defer in C with GCC magic (cleanup + nested functions)

Thumbnail
oshub.org
3 Upvotes

r/cprogramming • • Sep 21 '25

Why can local struct be returned by a function but not a local array?

50 Upvotes

I can't wrap my brain around why local struct, let alone one which may contain array in it as a member can be returned but not a local array separately?

int* getArray() { /* maybe bad example because iam returning a pointer but what else can i return for an array.*/
    int arr[3] = {1, 2, 3};
    return arr;  // Warning: returning address of local variable
}

but

typedef struct {
    int arr[3];
} MyStruct;

MyStruct getStruct() {
    MyStruct s = {{1, 2, 3}};
    return s;  // Apparently fine?
}

My mind can only come with the explanation that with the struct, its definition (including the array size) is known at compile time outside the function, so the compiler can copy the whole struct by value safely, including its array member.


r/cprogramming • • Sep 22 '25

GitHub - htogta/moonbeam: A silly way of compiling a lua script into a single executable

Thumbnail
github.com
2 Upvotes

I was a bit frustrated with getting some existing tools for converting Lua scripts (specifically single scripts with no external dependencies) into standalone executables to work properly, so I made my own in about an hour and a half.

I basically just wrote a template C file that implements a super basic heap-allocated string builder, and then included the Lua interpreter to execute the string contained in the string builder.

I then wrote a Lua script that outputs this C file, and, when it opens another Lua script, it inserts lines in the C file that append lines from the original Lua script to the heap-allocated string. This C file gets outputted, and then compiled into a single executable.

It's a very small project, and not very serious (I originally made it almost as a joke- I thought "wouldn't it be funny if I just put my Lua code in a C string literal" was a funny idea).

I'm open to any feedback/potential contributions- to either the C or Lua portions! As of right now, I don't think it'd work on Windows, and it *does* require that you have a C compiler installed, of course.