47 questions from the last 7 days
0
votes
0
answers
60
views
Does macOS have an equivalent of __FreeBSD_version? [closed]
FreeBSD defines the __FreeBSD_version macro in sys/param.h (as described here).
Does macOS have any equivalent?
At the moment I'm using uname -r at configure time to distinguish between major versions ...
Best practices
1
vote
4
replies
97
views
How to declare an array of structure to keep track for the end?
I'm trying to have an array of structure.
The sprite_s struct:
typedef struct sprites_s {
bool *initialized;
sfSprite *duck;
} sprites_t;
Can I, with memset, fill the array with data so I can ...
5
votes
1
answer
152
views
Is this a well-defined way to access bitfield bits by index in C11
The order of bits in C11 bitfields is implementation-defined, and so is any padding in between them. This makes it difficult to access the bitfields by index at runtime, even though most ...
2
votes
1
answer
90
views
_Generic in C is making me go insane [duplicate]
Take a look at my code:
#include <stdio.h>
#include <stdlib.h>
#define add_int(a, b) ((a) + (b))
typedef struct matrix
{
int** data;
int n_rows;
int n_columns;
} matrix;
...
2
votes
1
answer
100
views
Trying to learn how getchar works
I am encountering a problem inside a while loop that is embedded in a for loop iterating through a struct of arrays. The issues I am coming across is before the array iterates again, I want to have ...
Advice
1
vote
18
replies
237
views
Is there a reason why signed integer is used for the ssize_t?
From the man pages, I found that size_t has the range of 0 to SIZE_MAX, and ssize_t has the range of -1 to SSIZE_MAX. So, after printing those values on a 64bit system, I have the following results:
...
1
vote
0
answers
66
views
How To Create Progress Into Thread In UEFI For Multitasking [closed]
UEFI By Default Starts OS With Single Core And Is Harder To Multitask In UEFI Using Start Progress In Thread. I am making OS Form Scratch For Multitasking But There Is No Option To Multitask In EDK 2 ...
0
votes
1
answer
145
views
Input memory leak? [duplicate]
In my homework assignments I've got a task to get an input using scanf() of an integer number and check if its a positive negative or zero.
I've coded this:
#include <stdio.h>
int main()
{
...
Best practices
0
votes
11
replies
135
views
In C with stdarg, how can I pass a va_list to another function safely?
man stdarg shows, under the va_args macro description:
If ap is passed to a function that uses va_arg(ap,type), then the value of ap is undefined after the return of that function.
If we look at ...
2
votes
1
answer
136
views
Accurate computation of the inverse gamma function with the standard C math library
The inverse of the gamma function over the reals is multivalued with an infinite number of branches. This self-answered question is about the principal
inverse of the gamma function, Γ0-1(x), whose ...
Advice
0
votes
3
replies
100
views
Misunderstanding System V x86_64 ABI
My question is how this structure passed and returned from function?
struct S
{
int a[5];
};
I read ABI. As far as I understand if the size of structure less then 64 bytes it will separate to ...
1
vote
0
answers
44
views
Why doesn’t rlgl 2D drawing appear when using Raylib Camera2D?
I'm trying to batch some textures together in raylib (2d game) and so it tried using the 2d rlgl and for some reason that I can't figure out why nothing is getting drawn. I looked at examples and ...
7
votes
1
answer
123
views
If I start two strictly CPU bound threads bound to the same CPU, and one is SCHED_IDLE, why does it ever schedule?
If I start two threads bound to CPU 0, where one is SCHED_IDLE, then why is it ever scheduled when the other thread is CPU bound at either normal priority, or at SCHED_FIFO?
For SCHED_FIFO I get it, ...
1
vote
0
answers
65
views
WebKit2 Transparent window ghosting/after-image after DOM updates
I have successfully created a GTK window, made it paintable, created a WebKitWebView context, made sure it was completely transparent, and managed to render only the elements of the DOM inside the ...
3
votes
2
answers
108
views
Code is returning "[C Kernel] Executable exited with code -11", don't know what's wrong with it?
I'm working on this piece of code as part of my coursework, ideally any advice I get for this would be educational in some way; I don't want an exact answer, just need someone who knows more than I do ...
1
vote
1
answer
119
views
Why does my multithreading/pointers code print random values?
My code should print the numbers given as command line arguments. Instead it prints random-looking values.
What is going on and how can I fix it?
#include <stdio.h>
#include <pthread.h>
#...
-2
votes
3
answers
204
views
Why does float f = 3.14; and float f = 3.14f; print the same value in C even though one is double and the other is float?
I am confused about the following behavior in C.
#include <stdio.h>
int main() {
float a = 3.14; // literal is double
float b = 3.14f; // literal is float
printf("%f\n"...
-4
votes
0
answers
84
views
Tool to visualize C pointers, structures, enums, typedefs, etc [closed]
I'm working on an embedded (uBlaze running FreeRTOS on an FPGA) project in C, and there's a complicated network of structures, pointers, and "objects"* with complicated interdependence.
Part ...
1
vote
2
answers
93
views
How to handle N buttons with separate actions in pure C on Arduino without writing N ISR wrappers?
I'm working on an Arduino project in pure C with multiple buttons. Each button has a different action associated with it, and I want to handle button presses using interrupts.
Currently, the typical ...
-3
votes
0
answers
56
views
Trying to use ncurses getch or scanw to capture user input to confirm user permission for file overwrite
I'm trying to use ncurses.h in C to capture the user's key press to confirm if a file should be overwritten or not, for a terminal based audio recording/playing program. The way I've implemented is I ...
4
votes
2
answers
109
views
Is it possible to have a combine() function for CRC64/NVME
AWS S3 uses CRC64/NVME for its default checksum algorithm.
I need to send a trailing CRC64/NVME checksum.
The kicker is that I am middleware. There are multiple threads that are sending bytes. I ...
1
vote
1
answer
35
views
kretprobe executes the entry_handler function, but it doesn't execute the handler function
I'm interested in the arguments and the return value of the function __bread_gfp, so what i did was install an entry_handler for the arguments and a handler for the return value. Here's my code:
#...
-2
votes
1
answer
53
views
Not able to get Segger SystemView working on Freertos on STM32L0 in STM32Cubeide
I'm trying to get the segger systemview working on a STM32L073RZ nucle board with FreeRTOS. I have verified that freertos is working fine with the MCU as I could create 2 tasks and run them ...
Advice
0
votes
2
replies
56
views
How do I upgrade the cygwin package
I have cygwin 3-0-0 version and wish to keep all packages under the cygwin and only upgrade 3 packages, but i am confused on what to select. I need to upgrade them for CVE fix( xz utils and gawk)
I ...
3
votes
0
answers
71
views
Problems justifying text in GTK
System: Linux, Language: C, Toolkit: GTK
I am working to create an emulator for an embedded machine's display. The display is a smart 800x400 pixel RGB display.
The machine sends commands to control ...
-6
votes
1
answer
119
views
display different combination in c [closed]
Idk the structure to drive this. it should display like 00 01, 00 02, ... 01 99, ..., it finishs by 98 99.. just help me with the algorithm please
void ft_print_comb2(void)
{
char a,b,c,d;
a='...
-1
votes
0
answers
104
views
How efficient are pipes and threads in C compared to regular function calls or pure sequential code? [closed]
I’m currently studying Operating Systems at college, and my professor has started teaching us about threads and pipes in C.
His teaching style is very practical — he expects us not only to understand ...
-1
votes
0
answers
80
views
controlling and managing dependencies in projects
#include <SDL2/SDL.h>
Like everyone I typed brew install sdl2 but still gives me the error
--cannot open source file "SDL2/SDL.h"
Is there any magical way of controlling every ...
1
vote
5
answers
179
views
How can I tell my compiler or linker, that some symbol reference is only necessary for some function?
Suppose I'm working a library; say it's in C for simplicity. This library exposes and defines two functions:
f(), which calls an auxiliary function aux(), declared but not defined by my library.
g() ...
0
votes
1
answer
169
views
Identifying a failed null check
I am working on a function that must read one line at a time from a file, give the file descriptor of said file as input.
Here is my get_next_line function, and helper functions on top of it
# include ...
3
votes
0
answers
74
views
Can I modify host data after cudaMemcpyAsync
Can I modify host data in host_data_ptr after the following ?
cudaMemcpyAsync(device_data_ptr,
host_data_ptr,
size,
cudaMemcpyHostToDevice,
...
3
votes
2
answers
93
views
Why do I get a Run-Time Check Failure #2
Im new to C Programming and the Windows API im getting "Run-Time Check Failure #2 - Stack around the variable 'pMyStringAdress' was corrupted." after compilation in Visual Studio
Thats my ...
3
votes
2
answers
120
views
How can I correctly load the kernel to its canonical high address space
I am working on a small os with a custom boot loader targeting BIOS. For this, I need to map the kernel to its canonical high address space (0xFFFFFFFF80000000) and jump to its entry point.
For this, ...
0
votes
0
answers
48
views
wrong transformes for model loaded with assimp in opengl
Im trying to apply the model's transforms by walking the node heirarchy, but the poses are wrong (im not trying to animate it, just load it in a pose by using the transforms given in the gtlf file)
...
Best practices
1
vote
7
replies
157
views
Memory allocation when using a linked list
So I'm making a linked list for one of my school assignments in C. I found this website that has some helpful code snippets, and I noticed that they use malloc() to allocate more memory every time ...
1
vote
1
answer
97
views
Libav* encoding to FLAC results in MD5 Signature Mismatch
I am trying to learn how to use the FFmpeg libav* libraries but have encountered an issue when encoding to FLAC audio.
Running FFmpeg 5.1.7
I have copied the transcoding.c example from https://www....
0
votes
1
answer
120
views
Manual strstr implementation in eBPF on kernel level
I am trying to implement a manual implementation of strstr in eBPF but cannot get past verifier.
Before starting, I know there is an existing bpf_strstr() implementation, but it's on 6.17+ linux ...
6
votes
1
answer
212
views
MSVC doesn't follow NAN convention
The following code prints
1.000000 when compiled with gcc (trunk)
1.000000 when compiled with clang (trunk)
NAN when compiled with msvc (latest)
#include <stdio.h>
#include <math.h>
#...
2
votes
2
answers
145
views
Simple C malloc question that prints garbage on multiple invocations [closed]
I'm refreshing my C skills (been decades) and ran across something I don't quite understand. I'm working on some code that involves a lot of bit shifting, masking, etc. I have one function that ...
-1
votes
3
answers
69
views
Trying to read character and turn it into a string
static char* convert_to_string(const volatile uint8_t *ch)
{
static char read[40]; // static so pointer remains valid after return
uint8_t i = 0;
while (*ch != ESC || *ch != END_OF_TEXT ||...
Advice
0
votes
3
replies
87
views
Restrict keyword and pointers to pointers
I'm in C and I have an int ** (2 dimensional array, it's basically a matrix, it's actually set up a little bit complicated but there's no internal aliasing, so it's not relevant).
is this int** ...
2
votes
2
answers
78
views
mallopt(M_PERTURB) does not perturb the memory on free
I am trying to catch memory-related bugs such as use-after-free by mallopt(M_PERTURB, <value>).
According to the doc, the memory will be initialized to value when it has been released by free.
...
3
votes
1
answer
90
views
PowerPC/PPC64: The actual bit-ordering/numbering of the POWER9 registers from the programmer POV
Consider the following MSR register (the register's value is for the sake of example):
0x0400000000000000 -> MSR[58] = 1 -> Instruction Relocation for MMU is activated.
Now imagine I want to ...
1
vote
0
answers
110
views
STM32H7 UART RX not receiving data while TX works
TX works and prints info in console (I use Putty) but when I send on STM and echo I don't receive anything (and when I write symbols in console they don't appear). Baud rate and other config settings ...
Advice
0
votes
5
replies
84
views
How to assign unique elements to different indices?
I've been working on a program that prints out each word, their number of occurrence's and percentage of the number occurrences over total length of the sentence.
As you can imagine I had to create a ...
5
votes
1
answer
108
views
Symbol#to_s, Array#last, Time.now undefined or no-ops when evaluated using Ruby 3.x C API
For several years I've been using the Ruby C API to add the ability to use Ruby code in my C text editor (a variant of MicroEMACS). This has been working well in Linux Mint 21 (essentially the same ...
2
votes
1
answer
76
views
How do I portably parse a JSON file using libjq?
Consider the following code snippet based on libjq.
#include <stdio.h>
#include <stdlib.h>
#include <jq.h>
#include <jv.h>
int main(void) {
jq_state *jq = jq_init();
...