407,006 questions
0
votes
0
answers
39
views
How to correctly use memory mapped circular buffers without miscompilations [closed]
I tried compiling this code on gcc with -O3
#include <assert.h>
#include <stdint.h>
void square(uint8_t *array) {
assert(array[0] == 8);
array[1 << 15] = 4;
assert(array[...
-1
votes
0
answers
23
views
segfualt in C with GPU driver in vulkan [closed]
Unhandled exception at 0x00007FFE82E30508 (nvoglv64.dll) in Voxalith.exe: 0xC0000005: Access violation reading location 0x0000000000002068. I am writing a Vulkan application in C this file is device.c ...
0
votes
0
answers
6
views
Yocto Project: Linking a Shared Library to a Package Results in "library_common.h: No such file or directory" Error
I'm working on a Yocto project and need to create and link a shared library to one of the packages. The directory structure of the shared library source code is as follows:
library
├── svc
│ ├── src
...
0
votes
0
answers
20
views
How to compile sqlite3 source code for debugging in vscode
I have cloned sqlite3 codebase from github and ran following command on folder.
./configure --disable-amalgamation --debug
After that I have ran following command to build
make sqlite3
sqlite3 is ...
0
votes
1
answer
50
views
How make this text consistently line up? [duplicate]
I'm trying to display a row of data, I want to display the data neatly. I used \t, but using tab is inconsistent:
Current output (roughly):
Location City Price ...
1
vote
1
answer
29
views
Why does codeblocks memory dump window not show the error?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct train
{
int id;
int hours;
int minutes;
char destination[21];
};
// ...
1
vote
2
answers
79
views
In this code, why is scanf() not setting the input to the variable properly?
I am trying to post this to the C board. If I am in the wrong place, or this is not an appropriate question please let me know so can delete or move this. Thank you very much.
I am learning C as my ...
-4
votes
0
answers
49
views
zrle compression in C/C++ [closed]
I sniffed my VNC client and got a paylod of bytes that is ZLRE compressed VNC data. I want to decompress it, yet I dont know how to. I got this byte payload using wireshark and sniffing my unencryped ...
-1
votes
0
answers
38
views
Programming µcontroller (CH552): clock_t gives syntax in .c [closed]
I googled this question and found quite a lot of topics, but nothing has helped thus far.
I have a macropad from a certain website for cheap and wrote other firmware over it through code I got off a ...
0
votes
1
answer
79
views
Is dividing an integer with value 0x80000000 an UB?
Here is the code
printf("%d", 0x80000000 / 10).
It prints a correct value with respect to its absolute value, but forgets to put a minus sign. Let's check if the original integer (signed) is ...
4
votes
3
answers
70
views
GCC C99 Disable compilation of main() without return
How to force gcc compilator throw error when int main() have no return statement. This code compiles without any errors
#include<stdio.h>
int main(){
printf("Hi");
}
I am using
...
-1
votes
0
answers
68
views
How to install and use C library in macOS? [closed]
I'm a beginner in C. I'm using macOS (Sequoia) and vscode.
Let's get to the point, I want to use zip.h library so I installed libzip through homebrew. (brew install libzip)
But my vscode and gcc still ...
0
votes
0
answers
24
views
is this a new line character input buffer? [duplicate]
enter image description here
when i entered number of columns, after hitting enter got the newline character within the input buffer.
enter image description here
i was expecting this kind of result.
...
2
votes
1
answer
85
views
Listing all permutations as a List in C
Struggling to identify what is wrong with my code. I want to understand why my intuition here is wrong. The reason I want to produce a bunch of list is to hopefully enumerate at the start. But what am ...
4
votes
1
answer
95
views
Segfault even though correct value in variable?
I have the following main.c:
#include <stdio.h>
#include <stdlib.h>
extern unsigned short addsub(int op1, int op2, char what, int *res, int *bit_count);
void print_flags(unsigned short ...
2
votes
0
answers
93
views
How can I force the compiler to keep my parameters in the same registers when returning?
I'm trying to write some weird code that I'm planning on using for a very simple JIT. It's a bunch of small bytecode handler functions that I'll use in the generated executable that will look ...
2
votes
1
answer
76
views
Is it correct to bind UDP and TCP sockets to the same address and handle them simultaneously?
I am trying to bind both UDP and TCP sockets to the same IP address and port, and then handle both types of connections. I have implemented the following code:
The main function initializes both ...
2
votes
3
answers
120
views
Is it well defined to cast generic function pointers to specifc signatures with void* params pointing to different types
EDIT: I learned a lot from the answers, and they are correct. The code as shown is not well defined, because void* is "not compatible" with square*, specifically because pointers to struct ...
1
vote
0
answers
86
views
How to know if a segmentation fault will happen? [closed]
I'm new in c programming and i am wondering if there is any sure way to know if a program will segfault.
I came to know about the "valgrind" function but some of my codes still encounter ...
-2
votes
2
answers
80
views
How to copy char data to a smaller char already defined in memory? [closed]
Maybe this is an easy one but i could not find solution.
in function :
int function(char **data)
{
char data_new[542] = {.......};
memcpy(*data, data_new, sizeof(data_new));
return 1;
}
It does not ...
0
votes
0
answers
15
views
Problems with checksum in ICMP packets in C [closed]
I'm trying to create an ICMP timestamp program in C but i am having difficulties with the checksum of the ICMP packet. After doing the checksum of the packet i do the checksum of the packet again ...
2
votes
2
answers
41
views
STM32F4 Multiple motors with cases
Below is the motordriver.c code I’ve written. My goal is to execute a specific scenario where sometimes 3-4 motors need to operate simultaneously. I have arranged this scenario using a case structure. ...
1
vote
0
answers
44
views
How do I decompress the body of a http response in C using Brotli?
Whenever I try to decompress the body of this HTTP response, BrotliDecoderDecompress returns BROTLI_DECODER_RESULT_ERROR. However, I can't figure out what it is I'm doing wrong here.
// RECIEVE ...
1
vote
2
answers
71
views
error: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int *’ [-Werror=format=]
Compiling the below code without gcc flags doesn't raise any errors but does when I use -Werror, I have been printing memory address with %p flag but apparently I now have to typecast to void* to use ...
1
vote
0
answers
31
views
Meson can't find libm while cross-compiling
I've written a Meson build script to cross-compile a project.
Right now I have the full thing running but am having trouble finding libm "the proper way".
My toolchain is arm-none-eabi and ...
0
votes
0
answers
65
views
Mario less comfortable task - How to add space without typing in " " [closed]
My code works for the printing of hashes but it doesn't pass the check because of the additional space character(" "). I got the error:
"expected ""#"", not "&...
2
votes
1
answer
89
views
Can you compare two constant pointers in the C preprocessor?
Say my code looks like this:
gpios.h:
#define GPIO_BASE 0x08000100
#define GPIOA ((GpioRegs *) (GPIO_BASE + 0x04))
#define GPIOB ((GpioRegs *) (GPIO_BASE + 0x0C))
#define GPIOC ((GpioRegs *) (...
2
votes
0
answers
89
views
why does Python from C fail to load module?
PyObject *python_module;
char *module_filename = "/mnt/USB3/C/Python_from_C/python_processes";
Py_Initialize();
python_module = PyImport_ImportModule(module_filename);
if(python_module == ...
1
vote
1
answer
26
views
Relation of sigprocmask and pthread_sigmask for multithreaded program
sigprocmask(2) says:
Each of the threads in a process has its own signal mask.
, but also:
The use of sigprocmask() is unspecified in a multithreaded process; see pthread_sigmask(3).
...
1
vote
2
answers
39
views
SDL2 not throwing window close event
For personal use, I'm coding an additional layer on SDL2, which includes an event manager. It correctly detects every type of event, except SDL_WINDOWEVENT_CLOSE. After trying to debug my code, I ...
0
votes
0
answers
42
views
scanf not changing the value of a variable [closed]
In an attempt to help learn C I've been trying to write a simple calculator, but I'm stuck on the issue of scanf not assigning the inputted value to a variable.
I've seen people recommend fgets over ...
1
vote
1
answer
62
views
How to differentiate address sanitizer error from script error?
When using Address Sanitizer when either of ASAN or the actual program fails, the exitcode is always 1. How can I differentiate one from the other? I tried setting exitcode option in ASAN_OPTIONS to ...
2
votes
0
answers
45
views
How many cache lines does the adjacent cache line prefetcher bring into cache?
I was investigating the effectiveness of the adjacent cache line prefetcher and its impact on the number of cache lines prefetched from DRAM. Initially, I assumed it fetched only one more adjacent ...
0
votes
0
answers
77
views
This C code fails due to incompatibility with Windows 64 bit. Why? [closed]
[edit] - The problem was in how I was compiling. The problem is resolved when I use icx main.c fruits.c -o fruits.exe
I am attempting to implement a keyword management scheme in my C code similar to ...
3
votes
2
answers
84
views
Memory Lifetime within a process
I understand this might be an undefined behavior question, but I'm curious and also trying to understand the reason for the below results
#include <stdio.h>
#include <string.h>
#include &...
0
votes
1
answer
120
views
Why cant my long int handle the number 2971215073 in C?
So I have the following code:
#include <stdio.h>
unsigned long int fibonacci()
{
static int count = -1;
static int f1 = 0;
static int f2 = 1;
count++;
if(count == 0 || ...
1
vote
1
answer
27
views
Transparent textures do not render properly
I was using raylib and instead of partially showing the texture behind it's just black.
Output:
Expected output (made with an editor):
Here's my code:
BeginDrawing();
...
-1
votes
1
answer
70
views
How can these specific functions be convereted from using recursion to using iteration?
I've been working on porting a library from C to CUDA. Two functions that I need to port make use of recursion, which CUDA doesn't seem to be playing nicely with. I therefore want to convert these ...
2
votes
2
answers
39
views
Why doesn't SIGCHLD interrupt syscalls (i.e. read)?
When I receive a SIGCHLD blocking system calls like read doesn't return (with EINTR). If I get another signal they do.
It doesn't matter, whether the signal handler is set to a handler or to SIG_DFL. ...
-1
votes
0
answers
60
views
broken input in vscode when running C program [closed]
Is there any way to solve the following problem? I have a blockchain project in C, but I made a simple program below to demonstrate the problem. At some point, the inputs start to break and it becomes ...
2
votes
1
answer
90
views
C invert the bits of a 16 bit integer
This code won't simply invert the bits of the 16-bit integer as expected:
#include <stdint.h>
typedef uint16_t U16;
U16 myNum = 0xffff;
~myNum // 0xffff0000, not 0x0000
Because C will promote ...
1
vote
2
answers
60
views
Unexpected modification of the c language linked list
#include <stdio.h>
#include <stdlib.h>
// 定义DocNode结构
struct DocNode {
int doc_id;
struct DocNode* next;
};
// 创建新的节点
struct DocNode* create_node(int doc_id) {
struct DocNode*...
0
votes
1
answer
62
views
How do I update the value of a variable with each iteration
int main()
{
int n=50,k,l,A;
char ok;
printf("Is the number guessed %d?",n);
scanf(" %c",&ok);
for(int i=0; i<60; i++) {
if(i==0) {
...
1
vote
1
answer
50
views
Force readline to exit with signals
I am trying to get readline to exit when I press ctrl-c. I thought I could do this with rl_done but it is not working.
Upon pressing ctrl-c I am getting these debug statements:
start readline
setting ...
3
votes
1
answer
80
views
How to print constexpr in C23 at compile-time?
I'm migrating my codebase from C17 to C23 on ARM-GCC and would like to be able to print the evaluation of constexpr calculations at compile-time for debugging purposes.
In C17, I used #pragma message ...
1
vote
0
answers
20
views
Why doesn't syslog's LOG_PERROR option cause the log priority to be printed?
The standard library for syslog allows you to specify the LOG_PERROR flag which causes syslog calls to additionally write the log message to stderr. I'm able to get it to print the message just fine, ...
-4
votes
0
answers
43
views
Implicit Free List [closed]
Can someone explain to me how the number of Allocated Blocks are 6 and Free Blocks are 4 (according to the study guide answer). I have drawn out the allocated and free blocks in this
I got 5 ...
1
vote
1
answer
40
views
Behaviour of one-side socket close for UNIX socket with SOCK_DGRAM vs. SOCK_STREAM
When closing a UNIX socket on one side I would expect the other side to be notified of that by a read call, that returns 0. However when using SOCK_DGRAM, the read-call blocks indefinitely. Even when ...
0
votes
0
answers
55
views
How to check if 2 doubles are relatively equal in C language? [duplicate]
I'm working on some old C code that checks if two doubles are relatively equal. It works most of the time but sometimes it says the 2 doubles aren't equal even though the Print statement shows they ...
3
votes
1
answer
99
views
How to call vsprintf multiple times on the same argument list?
I would like a function I can call this way:
my_printf(int unimportant,
"%-10s", "a string",
"%5.1f", 1.23,
format_string, ...