Any C library function computing ceil(unsigned / double) or ceill(unsigned / long double)?

#include #include #define flt_precision_spec "%.57Lf" int main(void) { unsigned a=8222720U; long double b=65781.76L; printf("8222720/65781.76)=" flt_precision_spec ", ceill(8222720/65781.76)=%ld, and 65781.76*125=" flt_precision

Continue reading →

(GCC/Clang) Enforce type on variadic argument list?

This might be kind of a weird question, but I am a novice with __builtin_va_list and how it works. I am creating a function with the following signature: typedef signed char i8; typedef long long signed int i64; typedef lon

Continue reading →

Calculate buffer size for string in C

I need to build a string of numbers based on a for loop from 0 to n, something like this: char s[buffSize] for (i = 0; i< n; i++) { s+=i+'\s' // \00 instead of \s for last, i know this line of code is wrong in c } how would you calc

Continue reading →

In C/C++, why don't we usually cast dynamically allocated arrays to an array type instead of a pointer to the first element?

I am a beginner when it comes to C/C++. Still, when an array is dynamically allocated, why is the type typically kept as a pointer to the first element in the dynamically allocated block of memory? Instead, could it be cast to (a pointer

Continue reading →

How to reinitialize USB enumeration in STM32 Microcontrollers using only Software?

I am working on a USB Msc project that requires different USB sticks to be able to connect to the stm32f429. I am using HAL libraries. Some USB sticks require restarting or remuneration for File system operation. I want to restart the US

Continue reading →

shared memory questions - shm_open and msync

Background: Currently my application has a global array (which gets allocated using malloc) and is updated by almost all the functions in the application. The application also has a signal handler function that writes this array content

Continue reading →

How to init, and pass correctly 2D dynamic array in C?

I'm doing project to university which is Conway's Game of Life. Basicly the main function only contains game_main function. game_main declare the 2d dynamic arrays which are needed to game. In game_init function everything works right. B

Continue reading →

Forcing `pthread_create` to fail for test purposes

In order to test error recovery, I want to make pthread_create fail in a predictable manner. The most obvious way to do that is to put a hard upper limit on the number of threads that are allowed to exist in a specific process. On Linux

Continue reading →

Poll on named pipe keeps emitting events when all the data is read

I have the following code in which I create a named pipe (fifo) called /tmp/server-fifo and open it in non blocking read mode. I then poll for read events on the named pipe, and if there is an event, I attempt to read the data off the fi

Continue reading →

Reading the same file using multiple file streams for multithread applications

Context of the Problem: I have a large binary file containing data with a unique structure. A unit of this data is called an "event". Each event has 32016 bytes and a single file includes about 400000 events making the file ~12 GBs. I'm

Continue reading →

The C program is not displaying any output but it take the input Question from CS50 Lab1

Say we have a population of n llamas. Each year, n / 3 new llamas are born, and n / 4 llamas pass away. For example, if we were to start with n = 1200 llamas, then in the first year, 1200 / 3 = 400 new llamas would be born and 1200 / 4 =

Continue reading →