408,279 questions
1
vote
2
answers
225
views
How does MSVC's optimized asm implement a simple C program that uses strcpy on argv[1]? Understanding IDA output and what it's doing with pointers?
I have written a very basic int main program as shown below:
#include <stdio.h>
#include <windows.h>
int main(int argc, char** argv)
{
char buffer[500];
strcpy(buffer, argv[1]);
...
0
votes
0
answers
78
views
How do I make an alias that selects between a bunch of rules in bazel?
I have some cc_librarys that I wanna switch through depending on the platform. I was curious if there was any way to do this on bazel.
My end goal is to have something like
# Building a new library ...
1
vote
1
answer
180
views
Implementing authentication with SNMPv3 using lwIP on a STM32 MCU
Currently I'm working on a project which requires me to implement SNMPv3 on a STM32 microcontroller running FreeRTOS. (specifically STM32H563VIT6). I'm using lwIP stack to implement this protocol, ...
2
votes
1
answer
83
views
Subscribed to InterfaceAdded But no signal from dbus connection
My goal is to automate pairing and connecting between my device and controller via BlueZ to handle Bluetooth connection.
In order to do this, I thought of the most basic scenario:
execute the program
...
2
votes
1
answer
85
views
Error: expected string literal before '__asm' in a pico-sdk project?
In my RP2040 pico-sdk project, I'm getting a problem when I try to use the CMSIS function __DSB() - "error: expected string literal":
/src/MyProject/my_main.c:848:5: error: expected string ...
1
vote
0
answers
77
views
Creating a C chrome.dll forward-only wrapper give STATUS_STACK_BUFFER_OVERRUN
I was experimenting with writing a forward only wrapper that expose the function of the original dll, I decided to play with chromium "chrome.dll", my code seem to work, chromes open but ...
0
votes
1
answer
90
views
Mocking nested functions in a Hardware Abstraction Layer
I am using ceedling to unit test a file called adc.c that depends on functions defined in HAL file stm32h7xx_hal_adc_ex.c. The documentation says that I should only include the top level header file ...
3
votes
0
answers
210
views
How to cleanly shut down a real-time work queue?
I'm using the Windows Real-Time Work Queue API to do audio playback using WASAPI. The queue is created using RtwqLockSharedWorkQueue and work is submitted using RtwqPutWaitingWorkItem. From the ...
3
votes
2
answers
257
views
Is there a way to create a function in C wherein one variable can refer to one of any other variables depending on user input?
I am a beginner to C (and to proper programming in general, to a certain extent) and I am currently coding a vending machine program. The vending machine has three products, namely, A, B, and C, and I ...
1
vote
1
answer
121
views
Makefile to create .o and program file in separate directories depending on architecture of host PC
Trying to create a Makefile that compiles C source into a .o file in a subfolder as well as creating the executable in a different subfolder depending on the architecture of the host PC. When I run &...
2
votes
1
answer
101
views
OpenMP in C | How to keep private iterable after loop
So i'm working on some homework related to fixing som buggy code when i ran into an interesting problem. I don't think it was one of the indended bugs because the lecturer was confused by it as well. ...
0
votes
0
answers
119
views
Transforming tensorflow v1 graph and weights into saved model
I defined model (mnist digits recognition) using tensorflow 2.15.0 and tensorflow.compat.v1. Model was **not ** trained and the graph was exported using following code:
init = tf....
3
votes
1
answer
174
views
Cannot use external HWND function [closed]
I was making a Windows application but I get an issue. When I try to extern a function with HWND as a parameter, the linker report an error:
undefined symbol void far htest( HWND__ const near * )
I'...
4
votes
1
answer
112
views
Are spelling variations of encoding identifiers for "setlocale" standardized or documented?
This question has to do with syntactic conventions for string encoding identifiers in locale names passed to setlocale in C, focusing on the particular example of UTF-8. My preliminary observation is ...
1
vote
1
answer
172
views
Can you somehow grab a value from a register and put it into a C variable in C with the asm keyword for arm64 macOS assembly?
Can you somehow grab a value from a register and put it into a C variable in C with the asm keyword for arm64 macOS assembly?
I have seen code from other stack overflows that have already answered ...
0
votes
1
answer
82
views
Bounds-checking SDL_Surface::pixels?
In the SDL_Surface structure, is there
a way to calculate the bounds of the pixels
Member?
I need a quicker way of doing this, so my code doesn't catch seg-faults while running.
On my Linux Laptop, ...
-3
votes
1
answer
77
views
Libwebsockets client not see response on POST request
Minimal client (code below) send POST request, but not see response from the server. After LWS_CALLBACK_CLIENT_HTTP_WRITEABLE client waiting about 15 seconds and reset session. I see server answer in ...
2
votes
1
answer
72
views
Control memory of systemd sd_journal_open()?
When I use sd_journal_open() the process balloons in memory depending on the O/S and the flags used to open the journal.
I wrote a test that does nothing more than open the journal and idle in order ...
2
votes
1
answer
145
views
How to draw image to GDI properly?
I'm trying to use GDI to draw RGB images on Win32 window.
To draw, I first write colors to buffer in WM_CREATE and then draw it in WM_PAINT using StretchDIBits:
unsigned char imageData[46 * 32 * 3];
...
5
votes
1
answer
168
views
Why does using the %n conversion/format specifier cause a C/C++ program built with VC++ (MSVC) to crash?
I am trying to store the number of printed characters using the %n conversion specifier in C on Windows.
When I compile the following code with the VC++ (MSVC) compiler and run it, the program ...
0
votes
3
answers
254
views
What to use when malloc array length in c
When the array type is a "void *", then it can be allocated by:
void **void_array;
void_array = malloc(sizeof(void*) * 1);
But, if the array type is a struct Hello *, then what should be ...
15
votes
1
answer
394
views
Using OUTB to set cursor position in my minimal OS kernel causes QEMU screen to flicker
I am getting started with a minimal OS kernel (just gdt and place holder idt). Using i386 assembly and freestanding C. I wanted to change the position of the cursor for which i found several sites ...
15
votes
3
answers
2k
views
Why does a mismatching printf specifier also affect subsequent arguments?
I have a very simple C program where I am printing variables of different sizes.
#include <stdio.h>
unsigned int long long a;
unsigned int c;
int main() {
a = 0x1111111122222222;
c = ...
2
votes
3
answers
178
views
Bitwise operations act outside of type width in C; Compiler Bug or Within Spec?
The following derives from this question but is distinct
Consider the following code sample;
uint32_t *value = malloc(sizeof(uint32_t));
*value = 0xAAAABBBB;
int16_t *subset = (int16_t*) (value);
...
0
votes
1
answer
128
views
Linking Imgui correctly with pure c project using cImgui
I'm trying to use the latest version of cImgui, which supports Imgui 1.92.3 along CMake to link all the libraries required.
I got it compiling and now the compiler expects there to be external ...
4
votes
1
answer
136
views
Is it possible to have GCC inline vectorized trig functions?
Cosine and sine are computed with Horner's method and a Chebyshev polynomial, e.g. a0 + x(a1 + x(a2 + ...))). The fused-multiply add instructions this generates form a dependency chain, meaning we can ...
1
vote
1
answer
92
views
Why pthread_rdlock doesn`t downgrade the lock?
Code:
pthread_rwlock_wrlock(&memlock); // (1)
// do something...
pthread_rwlock_rdlock(&memlock); // (2)
// do something...
pthread_rwlock_wrlock(&memlock); // (3)
The following tags, (1),...
1
vote
0
answers
71
views
Is it okay to leave a struct unnamed when using typedef? [duplicate]
I'm naming a struct type with typedef, and I've been using them like this
typedef struct {
double x, y, z;
} vect3;
However I found out in other headers such as Win32, that it tends to be like ...
1
vote
0
answers
53
views
After establishing the libcurl websocket connection, data transmission and reception cannot be monitored through curl_multi_poll()
Websocket connection stage, curl_multi_poll() is useful for monitoring. However, during the data transmission and reception stage, curl_multi_poll() fails.
It is found that the CURL_POLL_REMOVE event ...
4
votes
1
answer
265
views
Implicit type casting within parenthesis and literals in C
The follow derives from the devkitpro 3ds filter audio example though it's not relevant to know exactly how the example works.
In short, consider this code:
size_t data_size = ...;
uint32_t data* = (...
4
votes
1
answer
147
views
how to implement syscalls with newlib nano
im trying to implement syscalls for printf so i defined the functions :
#include <stdint.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
void usart_init(...
1
vote
1
answer
121
views
can newlib-nano printf function work without heap allocation
i was looking at this heap implementation, and i was wondering if it is necessary to implement heap for printf even if i'm calling setvbuf(stdout, NULL, _IONBF, 0) before calling printf.
i looked at ...
7
votes
1
answer
230
views
Using zig to compile C to web assembly
I believe that it should be possible to use zig to compile a simple c library to web assembly.
I am using the following c code
// add.c
int add (int first, int second)
{
return first + second;
}
...
0
votes
0
answers
71
views
Touch Sensing on STM32
I’m working on a project using an STM32F072C8T6 for a smart touch board with capacitive touch sensors. I wrote code for touch sensing, but I’ve run into some issues:
The system sometimes takes some ...
1
vote
0
answers
86
views
PWM FSP code not working in ARDUINO UNO R4 WIFI
I decided to program a PWM using an ARDUINO UNO R4 WIFI. I tried to configure the RENESAS RA4M1 microcontroller with the FSP libraries through the Arduino IDE. What I want to do is generate a PWM and ...
1
vote
1
answer
113
views
Optional library without dlopen/LoadLibrary
Does Linux and/or Windows have a way to mark a dynamic library as optional, so that if it does exist, it is loaded and used to populate the symbol table, but if it does not, then the symbols are left ...
4
votes
1
answer
133
views
Why don’t pointers appear in Python Tutor’s memory visualization in C?
I’m new to C and I’m trying to understand how pointers work. In this piece of code, when I run it on Python Tutor (pythontutor.com) to see how the stack and heap work, I never see the pointer being ...
3
votes
1
answer
217
views
Java FFM - Unexpected behavior with "pointers" [duplicate]
To try out the Java 25 FFM API, I wanted to call C++ code through a C wrapper.
To do that, I created a small C++ class and a C wrapper following an example from here.
Printer.h
#pragma once
#include &...
5
votes
3
answers
323
views
The C 'Array-to-Pointer Decay' Paradox: Why do these function declarations behave identically? void func(char a[10]) vs void func(char *a)
I'm struggling to understand a core concept in C regarding Array-to-Pointer Decay when arrays are passed as function parameters.
It is well-known that when an array is passed to a function, it "...
5
votes
1
answer
138
views
Controlling color of menus in ncurses
I am working on a program to create menus with colors using ncurses on Linux:
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <ncurses/menu.h>
int main() {...
1
vote
0
answers
43
views
How can I modify the LED PWM configuration in the UF2 bootloader for the ATSAMD51J19A?
I'm working on a project using the ATSAMD51J19A with a UF2 bootloader, which appears as a storage device over USB for easy firmware updates. Currently, the bootloader sets an LED using a PWM signal on ...
4
votes
7
answers
270
views
How to define API in header and private fields in source in c
I want to define an API function in header file, and then implement it in source file.
Here is the hello.h, I want to define "world" in header:
typedef struct Hello {
int (*world) (void);...
4
votes
3
answers
151
views
Can you use a pointer representing a virtual object as the key in bsearch?
In C23, I have an array A sorted relative to a comparison function f. f has the property that if a certain address (say the address of a particular global variable) is passed to it, rather than ...
1
vote
1
answer
88
views
Swift 6 Strict Concurrency accessing C shared instance
I am trying to adapt C code, measuring pre/after main time, so it could be accessed from Swift with SC on. But nothing can silent compiler warning, indicating this code is not safe. I've tried every ...
1
vote
1
answer
205
views
How does getopt() function exactly work in C?
I am a beginner in the C language. I encountered the function
int getopt(int argc, char *argv[], char *options)
for parsing command-line options, and I am so confused about how it works.
#include <...
1
vote
1
answer
93
views
Get a Tk widget's associated CGContext
I've been working on a Tk widget that uses Cairo for more complex drawings as an extension to the standard Tk functions.
I've had great success on Windows and Linux, but not so much on MacOS. I need ...
-5
votes
1
answer
251
views
Which implementation of `strrchr` is correct?
To implement strrchr, it seems required to use casts, I have 2 implementations below, is there an objective reason to choose one approach over another?
char *Strrchr(const char *p, int ch)
{
char *...
0
votes
0
answers
84
views
x86 code generation, segfault when doing a PUSH instruction [duplicate]
Creating my own code area, jumping into it with CALL in assembly.
The RET alone works, but doing a PUSH fails with a segfault. Why?
int main() {
char* code = mmap(NULL, 4096, PROT_READ|PROT_WRITE|...
1
vote
1
answer
74
views
How can I remove the border on a GTK tooltip?
I am trying to precisely control the content of a GTK tooltip, but whatever I do, there is always a border remaining.
My real content is much more advanced, but the problem is 100% reproduced with ...
3
votes
1
answer
194
views
Understanding socket() function args
I need to use socket() but the args given to the function make me confused.
I have to do an school exercice where I have to use socket for intercept ethernet frame (more specifically arp spoofing).
...