408,305 questions
-4
votes
0
answers
50
views
Linux Sockets Correct Syntax Gcc Console App compiles with list of undefined errors unexplained? [closed]
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <netdb.h>
#include &...
-5
votes
0
answers
81
views
Why does it keep promting me? [closed]
When I run this code:
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int counter = 0; // Initialitzate counter
const int increment_every_time = get_int("What number do ...
2
votes
0
answers
59
views
Android (Linux) libc problems when creating an execuatable shared object
I have 2 files:
crt.c:
const char service_interp[] __attribute__((section(".interp"))) = "${LD_SO}";
extern void _exit (int __status) __attribute__ ((__noreturn__));
int main();
...
2
votes
0
answers
67
views
Packet corruption in Lockless ring buffer (multiple producer, single consumer)
I Am implementing Lockless ring buffer for multiple producer and single consumer (keeping in plan to extend it to multiple produce and consumer)
using design reference of dpdk buffer : https://doc....
1
vote
1
answer
51
views
The NEO-8M produces incomprehensible characters
I have that code:
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include "esp_system.h"
#include "esp_timer.h"
#include "freertos/projdefs.h&...
-2
votes
0
answers
79
views
Which compiler optimizations can break code without volatile when calling through function pointers? [closed]
Here is the code:
void (*volatile sys_func)(void);
void
main(int argc, char **argv) {
int i, j;
for (j = 0; j < 3; ++j) {
for (i = 0; i < 10000; ++i);
sys_func();
}
...
1
vote
0
answers
57
views
Possible to Use Source Files Outside the Workspace Root?
I'm trying to use C source files that are located outside my Ceedling project root. My repository has shared code in a common/ folder at the repo root, but my Ceedling project is in boards/CANGateway/....
Best practices
1
vote
12
replies
113
views
C memory initialization for a char** after a malloc
I've been researching this for a day and I've found a lot of conflicting information on multiple websites. I'm writing a simple test that will allocate and initialize a char** (array of strings, char*...
1
vote
0
answers
108
views
Monitoring changes to variables programmatically
This is a follow up to my previous question about creating a debugger for C source files in Python. The current issue I am facing is monitoring changes to variables. I want to monitor 8 variables say ...
-9
votes
0
answers
56
views
Unable to open Snapshot using VDDK [closed]
{"level":"error","ts":1764409482.772595,"caller":"vddk-service/service.go:125","msg":"Failed to open disk","error":"...
4
votes
3
answers
127
views
The reason of there being constraints on the second argument of `va_start()`
I've found that there are conditions that the second argument of va_start(ap, last) must satisfy, which are:
last must not be a register variable
last must not be a function
last must not be an array
...
-3
votes
0
answers
72
views
Whitesmith autoindentation of C/C++ code in VSCode [duplicate]
How can I get autoindentation to use Whitesmith style for C/C++ files in VSCode? I use Microsoft C/C++ Extension pack and clang-format. "Format Document" works ok with C/C++ files.
2
votes
1
answer
122
views
Is it possible to load a function symbol from an executable
I have 2 files:
foo.c:
#include <stdio.h>
int Main(int a) {
printf("A%dB",a);
}
int main() {
return Main(1);
}
bar.c:
extern int Main(int);
int main() {
return Main(2);
}
...
1
vote
0
answers
37
views
__TMS320C28XX__ are not defined at ccs20.3 when using F2800137 cputimer function [closed]
When I use the F2800137 DSP chip to develop a CPU timer code with ccs20.3 version, I find that the macro named __TMS320C28XX__ in cputimer.h file is not defined, which leads to me not being able to ...
-3
votes
4
answers
155
views
Would a 500+ case switch statement be possible with 8KB of CPU instruction cache? What alternative should I use?
Okay, this isn't exactly a typical programming situation. I wanna make a pokemon-like homebrew game for the nintendo DS (I know I could use C++, but I only know C so I'm just trying to code in C for ...
5
votes
1
answer
96
views
What is the performance effect (on x64) of __atomic_fetch_add that ignores its result?
My code is
...
fragment1 // compares several regions in D1$ to D1$/D3$
__atomic_fetch_add(&lock,-1,__ATOMIC_ACQ_REL); // stmt A
fragment2 // moves several regions from D1$/D3$ to D1$
...
3
votes
2
answers
188
views
Force the C compiler to read the object's memory
I duplicated the topic because (possibly) I made a mistake with the section of the site and initially posted in the wrong place: Ways to reliably read an object in C
I have a regular byte buffer ...
Best practices
1
vote
5
replies
141
views
Ways to reliably read an object in C
I have a regular byte buffer declared in file scope:
static unsigned char buffer[32];
At some point, the function to start a DMA read operation into this buffer is called:
void func(void) {
...
4
votes
1
answer
118
views
Why does thread 1 not exit?
I have a more complex situation that uses pthreads, synchronized with condition variables. Each thread had its own condition variable so there is no access problem.
The code runs a loop of 10 ...
4
votes
2
answers
133
views
Error with creating an array of named/predefined string constants in c
For background, I am working to create a version of minesweeper that runs in the terminal to become more familiar with coding bigger projects in c.
I am coding in VScode, to run on a Linux server (...
2
votes
0
answers
73
views
Database connection failing as soon as the parent ssh shell is terminated, even though I backgrounded and disowned
Alright, so bear with me. This took me an entire day to dig into.
what I'm doing
I'm running a C program on a remote host over SSH. The program calls a local redis database IP and port and also 8.8.8....
3
votes
1
answer
195
views
Why does sequential array access have a high cache miss rate?
I have the following C code that I am testing to understand perf and caching. It sequentially accesses an array of doubles.
// test.c
#include <stdio.h>
#include <stdlib.h>
#include <...
2
votes
0
answers
95
views
+100
In-Order Delivery of UIO Interrupts for Userspace Driver [closed]
I have multiple UIO interrupts defined. I am using Linux 6.12 without the realtime config (so, using the default scheduler, CFS).
My userspace driver is using poll in a loop to watch these interrupts ...
3
votes
2
answers
83
views
How do these 2 string buffers interact? Why does the internal logger buffer append to the buffer i dynamically allocate in main
So, for context, I have started writing a small HTTP-Server for learning purposes.
Currently, I have 2 modules: server and logger. The server module uses the logger I wrote internally for logging ...
-1
votes
0
answers
67
views
i686-elf-gcc "Error: invalid instruction suffix for 'push'/'pop'" [closed]
I'm following the barebones guide on OSDev Wiki and I'm trying to compile my kernel.c file with
i686-elf-gcc -ffreestanding -O2 -m32 -c kernel.c -o kernel.o
but I constantly get the following ...
1
vote
1
answer
121
views
How do I select the right language for my C program's output?
I am writing a C application, to be distributed as a single static binary (so it doesn't have a chance to do anything like install message catalog files). It only needs to support a few natural ...
3
votes
2
answers
108
views
Handling Buffer Size Errors in strftime: ERANGE vs EOVERFLOW
I have an application where I need to generate date and time based on the locale using the strftime function provided by C's time.h:
#include <stdio.h>
#include <time.h>
#include <...
Best practices
0
votes
5
replies
84
views
Should I pass as an argument a value that a macro can infer from the code?
Let's take a silly example:
#define MAX_NUM_BITES 20
...
void live_another_day() {
...
int num_bites = 0;
...
eat_little_pig(&num_bites);
if (num_bites>MAX_NUM_BITES) {
printf(&...
9
votes
1
answer
423
views
Getting notified when X11 window is minimized and restored
How can I get notified when the user minimizes or restores my X11 window? On very old Linux versions I could check for the UnmapNotify message to learn when the window is minimized and MapNotify when ...
2
votes
1
answer
54
views
MCP2515: normal Operation mode and Listen-Only mode
I have two ESP32S, each connected to a CAN driver (MCP2515 + TJA1050). One is constantly sending data, the other is constantly only receiving it. I want whoever receives the data to work in Listen-...
Tooling
1
vote
9
replies
136
views
need to update 8000+ C files -- clang-tidy?
I have inherited a project with over 8000 C source files from 26 years ago, so they have all kinds of old cruft that modern compilers (and best practices) won't put up with (old-style function ...
-3
votes
0
answers
58
views
Proteus HC-SR04 not showing distance property → LCD stuck on “System ready” [closed]
I am working on a PIC16F877A project in Proteus (bus stop detector using HC-SR04 + LCD).
The code is written in mikroC.
When I run the simulation, the LCD only displays “Systeme Pret…” and then ...
2
votes
1
answer
92
views
Is it undefined behaviour to free a `static restrict` array function parameter?
I'm asking this question from the perspective of a compiler developer – I want to know whether a particular potential optimisation is valid (because all programs that the optimisation would break have ...
0
votes
0
answers
37
views
GTK4 with gtksourceview5 in C: How do i change the style of the current highlighted line?
I tried using the GTK inspector to try and find the correct css node for but to no avail
I tried every selector i could think of like
.GtkSourceView.sourceview.view text .current-line
or even ...
0
votes
1
answer
100
views
Deferred cancellation in C [duplicate]
I am learning on how threads can be cancelled. Asynchronous cancellation can cancel the thread at any given point in time, but what I have learned about deferred cancellation is that it can only be ...
2
votes
1
answer
113
views
Accessing Union Members with Different Qualifiers in C
In the C standard (at least, I'm looking at draft C23 WG14/N3088), section 6.7.3 Type Qualifiers states:
7 If an attempt is made to modify an object defined with a const-qualified type through the ...
1
vote
2
answers
130
views
Everytime you define/declare a function, is there actually an extra memory spot reserved for every variable in the parameter you declare?
#include <stdio.h>
void update_score(int temp_score) {
printf("Inside Function: temp_score starts at %d\n", temp_score);
temp_score = 50;
printf("Inside ...
2
votes
2
answers
164
views
GCC warns of pointer reuse after realloc
I have this code in C11 (skipping references to pre-declared variables and functions):
// [...]
char *old_buf = it->buf;
shift += it->buf_size;
it->buf_size *= ...
Advice
0
votes
4
replies
191
views
Why does GCC transform a >= 4 into a > 3 at -O0? JG seems to be more complex than JGE
Title: Why does GCC transform a >= 4 into a > 3 at -O0? JG seems more complex than JGE
I'm analyzing a simple C code on godbolt and found GCC's code generation puzzling:
long a;
a = a >= 4;
...
-2
votes
1
answer
197
views
Is the C compiler allowed to emit spaghetti assembly for the sake of optimization? How can I get the compiler to perform such an optimization? [duplicate]
So I have the following code:
float param1 = SOME_VALUE;
switch (State)
{
case A:
{
foo(param1);
statement1;
break;
}
case B:
{
bar();
...
Advice
1
vote
5
replies
79
views
How to wrap C-library into SwiftPackage to use in my project?
I created test project - "TaoTester" and test package with C-library called "SwiftGit2".
After few days of work in package almost all works fine....
EXCEPT: I cannot link C-...
-3
votes
0
answers
85
views
How to solve UCB CS161 Project1 Questio6?I don't know what's the problem with my answer [closed]
here's the question and my answer,and i hope somebody to help me check my answer.i thought my thought procees was right,but something wrong happened
this my answer
payload = ""
payload += '...
5
votes
1
answer
206
views
Calling static function from inline function in C
In C, if I call a static function from an inline function, I typically get a compiler warning like
warning: static function <name> is used in an inline function with external linkage [-Wstatic-...
Best practices
1
vote
3
replies
119
views
What is the best option for handling multiple clients for a server in C?
I know that the current options are: creating a thread, a fork or a non-blocking socket?
What are the main advantages and disadvantages of all options?
What would be the recommendation for a small ...
2
votes
3
answers
203
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 ...
Advice
0
votes
1
replies
42
views
Adding stack information to jit'd code for sanitization
Disclaimer: I'm expecting that the answer to this question will be that it can't be done, but I'm asking as a just in case.
I am working on a JIT'd language with the compiler and runtime implemented ...
Tooling
0
votes
3
replies
98
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 ...
Best practices
2
votes
1
replies
49
views
How to properly obtain info on current user session lock using PAM
I have a C application that uses pam to reauthenticate a user on a system with faillocks configured. Imagine something that would work similar to login on the outside.
However, it only does basic ...
3
votes
1
answer
102
views
Does creating multiple JWT authentication tokens mean multiple server sessions for concurrent requests?
I'm participating in an online Sudoku-solving challenge where you create an account, and the server gives you a JWT token. Every request (getting the board, submitting answers, etc.) must include that ...
3
votes
2
answers
130
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 ...