408,283 questions
0
votes
0
answers
28
views
What are examples of non-finite float values other than infinity and NaN?
C23 §5.2.5.3.3 [Characteristics of floating types <float.h>] paragraph 8 says:
Floating types shall be able to represent signed zeros or an unsigned zero and all normalized floating-point ...
Tooling
0
votes
2
replies
45
views
Which IDE and tools for gcc C development?
Which IDE and tools are best suited for gcc C development? I currently use vscode and the tried using the ms-vscode.cpptools extension which "supports" gcc C. But extensions like nested ...
-2
votes
0
answers
47
views
How to properly implement reference counting in Linux kernel modules to prevent use-after-free vulnerabilities? [closed]
I'm developing a custom Linux kernel module for managing device resources, and I need to implement proper reference counting to prevent use-after-free (UAF) vulnerabilities.
My module maintains ...
2
votes
2
answers
112
views
Unexpected behaviour from minimax algorithm
I recently started learning C and as a learning project I tried creating a tic tac toe bot using the Minimax algorithm. Here is the code that I have written so far:
#include <stdbool.h>
#include ...
2
votes
2
answers
74
views
Can you construct a NULL-terminated GPtrArray that doesn't have an element_free_func?
I'm writing some C code where I want to have a NULL-terminated GPtrArray containing static strings. Typically, I would use g_ptr_array_new_null_terminated () to construct a NULL-terminated GPtrArray, ...
3
votes
2
answers
132
views
Accessing a union defined as a type [closed]
typedef union
{
unsigned long anyvariable;
float output;
} map;
return (*(map*)&fraction32).output;
I copied this method of accessing the members of a union which ...
Advice
0
votes
7
replies
113
views
C Preprocessor: foreach/macro expansion with loop context
So I've been using this code for generating such statements following This Reddit post:
#define LOOP(seq) END(A seq)
#define BODY(x) int x;
#define A(x) BODY(x) B
#define B(x) BODY(x) A
#define A_END
#...
0
votes
1
answer
88
views
RNG function creating the same sequence despite changes to seed [closed]
I am making an rng function in C with an upper bound. However, I'm always getting the same sequence of numbers - 3675356291. This is the file I'm using:
// The #include block. Contains the header ...
2
votes
1
answer
178
views
I can't find the memory leak [closed]
My function contain a memory leak, probably related to a failing malloc situation.
After extensive research and adding frees, I still can't find the edge case where the memory leak occurs.
Below is ...
Advice
2
votes
7
replies
117
views
Do all definitions of an inline function in C share the same address?
I know that it's possible to take the address of an inline function, just like with ordinary functions. But if each translation unit has its own inline definition, and I take the address of the ...
0
votes
0
answers
56
views
How does i in 'scanf("%d", ptr + i);' counts to 4? [duplicate]
I mean that i is incremented by 1 right, then how does ptr + i equals ith block of memory since int size is 4?
int i, n;
printf("Enter the number of Integers: ");
scanf("%d&...
Best practices
1
vote
4
replies
139
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 ...
2
votes
1
answer
112
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;
...
Advice
1
vote
22
replies
304
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:
...
0
votes
1
answer
157
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()
{
...
2
votes
1
answer
178
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 ...
1
vote
1
answer
55
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 ...
1
vote
0
answers
69
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 ...
1
vote
1
answer
126
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>
#...
-3
votes
0
answers
91
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 ...
-2
votes
0
answers
71
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 ...
1
vote
1
answer
42
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:
#...
Advice
0
votes
2
replies
59
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 ...
-5
votes
1
answer
120
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='...
0
votes
0
answers
84
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 ...