DS Log
In my blog, I delve into the world of programming web technologies, Linux, Unix-like, and graphic design using free tools on Linux.
KINGCODE
KingCode Editor (ex Texty Editor) is my project developed using Java Swing. Project is still in development and in beta version. I plan to add additional features focused for PYTHON, PHP, JAVA, C, JS and BASH.
Read more ↗
VUE on Linux
In this guide, I'll walk you through the step-by-step process of setting up Vue.js on your Linux system, empowering you to create dynamic and interactive web applications. Let's harness the power of Vue.js together on the Linux platform!
Read more ↗
Symfony PHP
Dive into the world of Symfony PHP with this comprehensive introduction. In this guide, you'll learn the essential steps to create and manage posts and users, empowering you to build dynamic web applications with ease.
Read more ↗
Trying Linux from Windows
How to set up a PHP development server on Ubuntu 22.04
Text editors
List of text editors for developers.
Read more ↗
Fonts
Important fonts everyone needs to know.
Read more ↗
Try Linux from Windows
Here are some quick videos I made showing how to try out Linux Mint on Windows.
Read more ↗
Friday, January 2, 2026
What are those "ARG1 | ARG2" wierd arguments in C?
In C, a bit-mask argument refers to passing an integer value to a function where individual bits (or groups of bits) in that integer represent boolean flags or options. This technique allows you to combine multiple settings into a single argument using bitwise operations.
How It Works
Each option is typically defined as a power of two (i.e., a number with only one bit set), so that each option corresponds to a unique bit position.
#define OPTION_A (1 << 0) // binary: 0001 (1)
#define OPTION_B (1 << 1) // binary: 0010 (2)
#define OPTION_C (1 << 2) // binary: 0100 (4)
#define OPTION_D (1 << 3) // binary: 1000 (8)
Combining Options
You combine options using the bitwise OR (|) operator:
int flags = OPTION_A | OPTION_C; // binary: 0101 (5)
This means both OPTION_A and OPTION_C are enabled.
Checking Options
Inside the function, you test whether a particular option is set using the bitwise AND (&) operator:
#include <stdio.h>
#define VERBOSE (1 << 0) // 1
#define UPPERCASE (1 << 1) // 2
#define DRY_RUN (1 << 2) // 4
void process_text(const char* text, int flags) {
if (flags & DRY_RUN) {
printf("[DRY RUN] Would process: %s\n", text);
return;
}
char buffer[100];
if (flags & UPPERCASE) {
// Simple uppercase conversion (for demo)
for (int i = 0; text[i]; i++) {
buffer[i] = (text[i] >= 'a' && text[i] <= 'z') ? text[i] - 32 : text[i];
}
buffer[strlen(text)] = '\0';
text = buffer;
}
if (flags & VERBOSE) {
printf("Processing text: %s\n", text);
} else {
printf("%s\n", text);
}
}
int main() {
process_text("hello", VERBOSE | UPPERCASE); // Enables both options
process_text("world", DRY_RUN);
return 0;
}
How many flags can you stack?
It depends on the size (in bits) of the integer type you use:
| Type |
Bits |
Max Distinct Flags |
| unsigned char / uint8_t |
8 |
8 |
| unsigned short / uint16_t |
16 |
16 |
| unsigned int / uint32_t |
32 |
32 |
| unsigned long long / uint64_t |
64 |
64 |
Another 32bit example
#include <stdint.h>
#include <stdio.h>
// Mouse buttons
#define LMOUSEBUTTON (1U << 0) // Left mouse button
#define RMOUSEBUTTON (1U << 1) // Right mouse button
#define MMOUSEBUTTON (1U << 2) // Middle mouse button
// Keyboard modifier keys
#define SHIFTKEY (1U << 3)
#define CTRLKEY (1U << 4)
#define ALTKEY (1U << 5)
#define SUPERKEY (1U << 6) // Windows / Command key
// Movement keys (WASD + arrows)
#define W_KEY (1U << 7)
#define A_KEY (1U << 8)
#define S_KEY (1U << 9)
#define D_KEY (1U << 10)
#define UP_ARROW (1U << 11)
#define DOWN_ARROW (1U << 12)
#define LEFT_ARROW (1U << 13)
#define RIGHT_ARROW (1U << 14)
// Action keys
#define SPACE_KEY (1U << 15)
#define ENTER_KEY (1U << 16)
#define ESC_KEY (1U << 17)
#define TAB_KEY (1U << 18)
// Common game keys
#define E_KEY (1U << 19)
#define Q_KEY (1U << 20)
#define R_KEY (1U << 21)
#define F_KEY (1U << 22)
#define MOUSE_WHEEL_UP (1U << 23)
#define MOUSE_WHEEL_DOWN (1U << 24)
// Extra (reserved for future use or custom actions)
#define CUSTOM_1 (1U << 25)
#define CUSTOM_2 (1U << 26)
#define CUSTOM_3 (1U << 27)
#define CUSTOM_4 (1U << 28)
// You can go up to (1U << 31) safely on 32-bit unsigned
// Optional: Combined masks
#define MODIFIERS_MASK (SHIFTKEY | CTRLKEY | ALTKEY | SUPERKEY)
#define MOVEMENT_MASK (W_KEY | A_KEY | S_KEY | D_KEY | \
UP_ARROW | DOWN_ARROW | LEFT_ARROW | RIGHT_ARROW)
// Helper function to check if a specific key/flag is pressed
static inline int is_key_pressed(uint32_t input_state, uint32_t key_flag)
{
return (input_state & key_flag) != 0;
}
// Example: Check if running (W + SHIFT)
static inline int is_running(uint32_t input_state)
{
return is_key_pressed(input_state, W_KEY) && is_key_pressed(input_state, SHIFTKEY);
}
int main(void)
{
// Simulate an input state: Left mouse + Shift + W pressed
uint32_t state = LMOUSEBUTTON | SHIFTKEY | W_KEY;
if (is_key_pressed(state, LMOUSEBUTTON))
{
printf("Left mouse is pressed\n");
}
if (is_running(state))
{
printf("Player is running forward!\n");
}
// Additional example checks
if (is_key_pressed(state, SHIFTKEY))
{
printf("Shift key is held\n");
}
return 0;
}
Notes:
* All values use 1U (unsigned) to avoid undefined behavior with shifts ≥16 on some systems.
* Stays safely within 32 bits (bits 0–28 used above; bits 29–31 are free).
* You can add more (e.g., 1U << 29, 1U << 30, 1U << 31) if needed.
* Avoid 1 << 31 without the U suffix — that’s a signed overflow!