#include — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #include, aggregated by home.social.
-
picking my way through a Windows C++ project on Linux and of course finding that the developer ignored case on include files:
#include "Ram.h"
but the file's called RAM.h
aargh.
Also, there's no way to convert sln files to Makefiles under Linux. Arse.
-
Damn you gcc...
$ cat x.c
#include <stdio.h>
int main() {
printf("hello world\n");
}
$ gcc -o x x.c
$ strings x | grep GCC
GCC: (GNU) 14.3.1 20251022 (Red Hat 14.3.1-4) -
@tymoty Slo by to i v C. Jen teda ne takhle :-). Nejlepsi asi libsdl, zacit od nejakeho prikladu z dokumentace, nebo LLM neco vygeneruje...:
// gcc main.c -o main -lSDL2
#include <SDL2/SDL.h>
#include <math.h>
#include <stdio.h>
#include <stdbool.h>
int main(int argc, char** argv) {
(void)argc; (void)argv;
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("SDL_Init failed: %s\n", SDL_GetError());
return 1;
} -
@pavel , děkuju!
(Python nevylučuju, ale radši bych se mu vyhnul.)
Nešlo by to v tom C?
Našel jsem nějaký takovýhle příklad:
#include <xf86drm.h>
#include <xf86drmMode.h>int main() {
drmModeRes *resources;
int fd = open("/dev/dri/card0", O_RDWR);
resources = drmModeGetResources(fd);
}---
#tg438982836 Program. Je v program.txt . -
Sorry about it, but I did modify a C Nested Structure in order to learn how...It worked out rather well after I figured out my mistakes. It took me forever to get to that. Here is the base example...I won't show you my modified example because, yeah. It's kinda lewd and that would be rude!
#include <stdio.h>
struct Owner {
char firstName[30];
char lastName[30];
};struct Car {
char brand[30];
int year;
struct Owner owner; // Nested structure
};int main() {
struct Owner person = {"John", "Doe"};
struct Car car1 = {"Toyota", 2010, person};printf("Car: %s (%d)\n", car1.brand, car1.year);
printf("Owner: %s %s\n", car1.owner.firstName, car1.owner.lastName);return 0;
}Expected Output:
Car: Toyota (2010)
Owner: John Doe -
CW: I'm like if Alvin Toffler didn't expect to particularly enjoy the envisioned future
Code was never the problem. It will never be the problem.
Writing good spec is part of the problem. Code reviews are the other part.
I'm sick of tight code. I want to see legible, spec-ed code. If I saw bullshit on this order I would send it back:
#include <stdio.h>
typedef struct { int id; double rate; const char *label; } TxnParams;
double apply_rate(TxnParams p, int (*validator)(const TxnParams *), double table[static 3]) {
if (!validator(&p)) return -1.0;
return p.rate * table[p.id % 3];
}int always_valid(const TxnParams *p) { return p->id >= 0; }
int main(void) {
double result = ((double (*)(TxnParams, int (*)(const TxnParams *), double[static 3]))apply_rate)(
(TxnParams){ .id = 7, .rate = 1.0725, .label = "EDI850_LINE" },
always_valid,
(double[3]){ [0] = 100.0, [1] = 250.0, [2] = 500.0 }
);printf("%.4f\n", result);
return 0;
} -
@solonovamax whatever you do, never ever do anything where u need to write "#include <Arduino.h>" when doing stuff with esp32. Arduino has some very very horrible code that I needed to patch so often that it just hurts. Like the amount of times I screamed because some Arduino bs is insane. Very much can recommend the ESP-IDF
-
I learned how to work with C Structures, overcoming my maximum distraction. The solution to the small challenge was to create a C Structure that had all the means of printing the outcome- Person age: 25.
This is my work:
#include <stdio.h>
struct Person {
int age;
};int main() {
struct Person p;
p.age = 25;
printf("Person age: %d", p.age);
return 0;
}Now, I am moving on to C Nested Structures, which will be even more nuanced. I will probably start it tomorrow though...As I just want to have fun. ROFL
-
I nearly didn't understand why my whole file wasn't being read to me with the: #include <stdio.h>
int main() {
FILE *fptr;// Open a file in read mode
fptr = fopen("filename.txt", "r");// Store the content of the file
char myString[100];// Read the content and print it
while(fgets(myString, 100, fptr)) {
printf("%s", myString);
}// Close the file
fclose(fptr);return 0;
}I didn't realize that I left a conflicting command in the above sample: fgets(myString, 100, fptr); That was the source of my problems. The reason why only part of my text was printing. LOL What a time to be the most goose on the loose that there ever was! Clearly time for a rest.
-
I also learned how to use compare() and qsort() which are part of the C Standard Library <stdlib.h>. That was fun, though something that really fascinated me for future usage is: How to create files using C:
#include <stdio.h>
int main() {
FILE *fptr;// Create a file on your computer (filename.txt)
fptr = fopen("filename.txt", "w");// Close the file
fclose(fptr);return 0;
}I don't know why this basic function is so interesting to me, but it is. I already used it to create a file with a unique name (that I won't tell anyone). It's neat, I might learn how to further mess with files before giving my brain a break for today.
-
Okay, looking at Callback Function now, which is really freaking cool!
#include <stdio.h>
void sayHello() {
printf("Hello from the callback!\n");
}void runCallback(void (*callback)()) {
printf("Before calling the callback...\n");
callback();
printf("After calling the callback.\n");
}int main() {
runCallback(sayHello);
return 0;
}Expected Output:
Before calling the callback...
Hello from the callback!
After calling the callback.In order to test it properly, I created a little micro story using the callback function (I won't share, I like ya'll). Just to test how it works. As I used it in two ways. To print the micro story out of order and in order using the callback feature. So that I could make sure that I understood what the function was doing. It's pretty neat! I can see myself using this in a text based game...
-
So here it is, a very simple calculator with variables hardcoded in with three options: Add, Subtract, Multiply. I naturally made a few changes.
#include <stdio.h>
void add(int a, int b) {printf("Number Sage Divination: %d\n", a + b);}
void subtract(int a, int b) {printf("Number Sage Divination: %d\n", a - b);}
void multiply(int a, int b) {printf("Number Sage Divination: %d\n", a * b);}int main() {
int choice, x = 64, y = 3;void (*operations[3])(int, int) = {add, subtract, multiply};
printf("x = %d, y = %d\n\n", x, y);
printf("Number Sage asks for a Divination Method:\n\n");
printf("0: Sacred Add\n1: Unholy Subtract\n2: Godly Multiply\n");
scanf("%d", &choice);if (choice >= 0 && choice < 3) {
operations[choice](x, y);
} else {
printf("Invalid Divination Method!\n");
}return 0;
}Expected Output:
x = 64, y = 3
Number Sage asks for a Divination Method:
0: Sacred Add
1: Unholy Subtract
2: Godly MultiplyI'm having fun this afternoon!
-
Now w3schools is starting to build on the basics by giving a template to try that shows the potential of creating a simple interface that will eventually turn into an interactable calculator program:
#include <stdio.h>
void add() {printf("Add\n");}
void subtract() {printf("Subtract\n");}
void multiply() {printf("Multiply\n");}int main() {
void (*operations[3])() = {add, subtract, multiply};
for (int i = 0; i < 3; i++) {
operations[i]();
}
return 0;
}Expected Output:
Add
Subtract
MultiplyAs you first need to print these options, then build upon this by adding more functionality to it. It's actually very nice of them to gradually curve the difficulty up to this point. I deeply appreciate that from them!
-
Huh, I think I get the point of passing an argument as a function as I completely customized this example and it still worked (won't share the customization because...Yeah, that wouldn't be kind). I love being able to customize the examples in a way that makes my brain jump for joy. So I will share the basic example that can be customized:
#include <stdio.h>
void greetMorning() { printf("Good morning!\n"); }
void greetEvening() { printf("Good evening!\n"); }void greet(void (*func)()) {
func();
}int main() {
greet(greetMorning);
greet(greetEvening);
return 0;
}It's one of the simplest to substitute in because punctuation doesn't affect much for the printf parts. If you do change the void "greetMorning/Evening " parts you just need to make sure the first part remains the same between the two. As the start of the function will be referenced in the 7th line, and then you'll need to alter line 11 and 12 so that an altered example worked properly. I could see one even making a haiku by adding a third function and writing the printf sections in the style of "5, 7, 5". It's a very versatile example to play with.
-
I was reading about how inline functions can be executed faster when they are frequently required by one's program, but they also can sometimes not be dealt with well by compilers or debuggers in IDEs. Eclipse's debug could not handle:
#include <stdio.h>
inline int add(int a, int b) {
return a + b;
}int main() {
printf("%d", add(5, 3));
return 0;
}As it couldn't figure out that the "inline int add" function and "add" were already connected. Even after manually doing that. It was really weird, so I couldn't execute the code in Eclipse. In the future, I suspect that I'll have to make some more custom modifications to the Eclipse debugger in order to use C Inline functions. As the default debugger for this current configuration in Eclipse can't deal with them.
-
I think i just found a GCC bug?
#include <cmath> #include <cstdio> namespace ligma { using ::std::round; } int main() { double h = ligma::round(5.5); fprintf(stderr, "%f\n", h); }This code compiles in GCC 15.2.0 but not GCC 16.1.0 (both in C++17 mode)