408,284 questions
1
vote
6
answers
189
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() ...
3
votes
0
answers
87
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
122
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, ...
Best practices
1
vote
7
replies
161
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 ...
0
votes
1
answer
123
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 ...
2
votes
2
answers
149
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 ...
Advice
0
votes
3
replies
89
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** ...
3
votes
1
answer
92
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 ...
Advice
0
votes
5
replies
86
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 ...
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();
...
Best practices
1
vote
7
replies
124
views
Is there way to remove coredump generation for SIGQUIT for C program
I have automated tests for fairly complex software, which send SIGQUIT signals at program startup. If the signal arrives before the handler is installed, a coredump is generated, causing the test to ...
0
votes
1
answer
120
views
Why Cuda threads are repeating same task?
I have a coded my simple CUDA ZIP password cracker but it seems that it prints same password for a number of times and i couldn't figure out why and this is weighing down my program.
Here is the full ...
Best practices
1
vote
3
replies
98
views
How to deal with an intense CPU consuming task triggering watchdog?
I am using esp-tflite-micro to make some inferences, but it is taking too much time to finish a single inference; enough to trigger the watchdog of the idle tasks.
I know I may increase the watchdog ...
0
votes
1
answer
91
views
How to choose appropriate EGL config for GPGPU on GLESv3.1+?
I am working on a simple OpenGL ES v3.1+ setup to use it for GPGPU purposes on a headless system. (Note: Uses proprietary Mali Valhall G610 drivers on Debian 12)
The GPU supports the ...
3
votes
2
answers
156
views
Recursive C function for creating number permutations
I do understand I have mistakes in this code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int diziyi_yazdır(int dizi[], int dizi_uzunluğu)
{
for (int i ...
3
votes
3
answers
197
views
strlen() returns 1 larger on linux than windows
I am building a c extension for a python module and it needs to work the same on a windows machine and on a raspberry pi.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#...
3
votes
1
answer
114
views
Does clang-format always reformat array initializers?
Suppose I have a file test.c with the content below. I as a developer have formatted my firmware blob with 8 bytes per line so that when I want to find the byte at offset 0x25 I can easily locate it.
#...
1
vote
1
answer
51
views
C API duckdb_create_list_value is always returning NULL [closed]
I am trying to insert a list of values to a column INTEGER[]. For that I am creating list value as I need to use appender. But duckdb_create_list_value is always returning NULL. I am using v 1.4.1 C ...
Advice
1
vote
9
replies
112
views
Sum of a binary tree
I have a binary tree which leafs have a size of 1, and the parent double in size at each level.
I project those nodes on a linear axe (memory space).
I need to get the equation that gives the adress ...
0
votes
0
answers
173
views
VS Code isn't autocompleting or underlining errors
VS Code quit highlighting errors in the editor. Furthermore, autocomplete isn't working. I don't know if its a related issue, however, IntelliSense keeps getting stuck in its initialization phase.
...
0
votes
1
answer
92
views
gdi32 painted window not redrawing when unminimizing
I want my window to redraw the pixel put on the screen when WM_PAINT message is called after unminimizing my window. Cause all what i drawn is cleared when minimizing. I tried different thing, i think ...
2
votes
1
answer
106
views
C macro compilation fails in Clang with "expected ;" due to phantom comma in clang -E expansion
I wrote my "Result" macro header, using C23 and some of the newest features:
#pragma once
#include <stdio.h>
#include <stdlib.h>
#define __RESULT_EAT_PARENS(...) __VA_ARGS__
...
4
votes
3
answers
167
views
Why does my C code display the correct output, but with garbage characters added after?
The practice question I am working on reads as:
Read two strings, both of them do not contain white spaces (but may contain non-alphanumeric, such as ‘,’, ‘.’, ‘/’ ...).
Display the first string ...
-3
votes
1
answer
122
views
Best way to parse an http request (from scratch) [closed]
I'm currently working on a mini NGINX project just for learning purposes. I already implemented some logic related to socket networking. I'm now facing the problem of parsing the HTTP requests, and I ...
Advice
1
vote
9
replies
200
views
Is this array subscripting behavior really undefined in C?
unsigned int n = 1;
char* s = "X" + 1;
s[-n];
Is that third statement undefined in C23? It seems it is, as by the standard in 6.5.2.1.2:
... The definition of the subscript operator [] is ...