408,284 questions
1
vote
4
answers
189
views
Does union "common initial sequence" include bitfields?
As far as I understand, you are allowed to access inactive members of a union, if they share a "common initial sequence" with an active one. This can be used to tag active member with a type ...
0
votes
0
answers
71
views
IOCTL_ATA_PASS_THROUGH Returning ERROR_ACCESS_DENIED When Calling DeviceIoControl
I am trying to retrieve the SMART Data of an external SATA SSD
wchar_t path[64];
swprintf_s(path, _countof(path), L"\\\\.\\PhysicalDrive%d", 0);
HANDLE hDrive = CreateFile(path, GENERIC_READ ...
Advice
0
votes
2
replies
100
views
How to run and test Software Code and then put it in Hardware
I'm trying to build my own handheld games console similar to a gameboy.
Currently for the POC im using the Arduino Uno, seperate SD Card Reader Module and 2.4 inch TFT Display. I want to put the game ...
2
votes
1
answer
101
views
Macros not working as I expect on Windows
I have the below code I want to print Use skeleton! if SKELETON_ENABLED is defined and is not running on MAC OS, and Don't use skeleton!\n otherwise.
The program prints Don't use skeleton!\n, even ...
0
votes
1
answer
70
views
STM32 - I2S: Read signal from INMP441
I'm using STM32F103C8T6 to receive the signal from INMP441 with I2S. Using Standard Periph Library with keilC. I configured GPIO, I2S, Usart, I want to get data from INMP441 then send it to esp32 ...
Advice
0
votes
4
replies
137
views
Using lockless atomic operations instead of a mutex
I recently had an interview where I was asked to show how to prevent race conditions in C or C++ between two threads operating on shared data. I used a mutex as follows :
pthread_mutex_t mutex;
int ...
Best practices
2
votes
10
replies
274
views
How to tell the C compiler that data pointed to by a pointer won't be constantly modified by another thread after being passed to a function?
In C, when I pass a pointer to a function, the compiler always seems to assume that the data pointed to by that pointer might be continuously modified in another thread, even though in actual API ...
-3
votes
1
answer
108
views
Is the GCC bootstrapping 'chain' improved / simplified relative to 2021?
In 2021, this post here on StackOverflow:
How are GCC and g++ bootstrapped? -> Andrius Strikonas' answer
explained how GCC can be bootstrapped beginning with a tiny assembler taking just a hex dump ...
3
votes
1
answer
134
views
How to create a dialogbox main window in C using Visual Studio 2022?
I just installed Visual Studio 2022 and I'm trying to get an application working with a dialog box as a main window in order to make the GUI easier to produce. But the thing is that I've found nothing ...
5
votes
1
answer
104
views
Use Petsc-Library in Go
I am trying to use the PETSc (Portable, Extensible Toolkit for Scientific Computation) library in Go over cgo. After the call of PetscInitialize, the program will crash at a random point with the ...
2
votes
1
answer
112
views
Hide implementation similar to pimpl without heap allocafion
I am trying to hide some implementation behind an opaque data type. Normally, pimpl would be the preferred pattern, but it requires heap allocation which is not desirable in this context (embedded, ...
1
vote
1
answer
56
views
SNMPv3 requests sent to an STM32/LwIP agent time out, v2c works fine
I am implementing an SNMP agent on an STM32H563 using LwIP. SNMPv2c works perfectly, but SNMPv3 requests with the authPriv security level time out.
On the manager's side, a request is sent with net-...
-1
votes
0
answers
87
views
How To Safely Parse Double Input From User with scanf [duplicate]
double amountAdd = 0;
while (amountAdd <= 0) {
printf("\nEnter Amount to deposit: ");
scanf("%lf", &amountAdd);
}
In this block of ...
Advice
2
votes
10
replies
380
views
Visual studio vs gcc
I'm a small-scale C programmer at the moment, and I'm bugged by the question: is Visual Studio worth the annoyance that it is?
I've been programming in C and C++ in Visual Studio Code for a while, and ...
2
votes
2
answers
183
views
How to debug external program run in main function in C?
I want to add a breakpoint in the line system("/path/to/world") in VS Code for debugging the /path/to/world program with gdb.
Here is the source code of /path/to/hello.c:
int main(int argc, ...
2
votes
0
answers
208
views
how to execute x64 ABI assembly code on heap from C
I am creating heap allocated memory with execute rights using windows.h VirtualAlloc and VirtualProtect.
void* write_into_executable(uint8_t code[]) {
SYSTEM_INFO info;
GetSystemInfo(&info)...
1
vote
1
answer
134
views
Migrating from OpenSSL 1.1 to 3.0: How to generate DH key pair with 32-byte prime using EVP_PKEY-DH interface?
I'm migrating my Diffie-Hellman (DH) implementation from OpenSSL 1.1 to OpenSSL 3.0. Previously, I used APIs like DH_set0_pqg, but these are now deprecated. I am switching to the EVP_PKEY-DH interface ...
-5
votes
2
answers
270
views
How to try catch finally in c
I want to try catch the free(hello); so that the free(world); can still be executed for freeing all allocated memory in the main program.
int main()
{
const char *hello = "Hello World";
...
-2
votes
1
answer
174
views
strcpy with/without '\0' in c [duplicate]
When trying to copy the string with strcpy, the following code will get the same result in the output. It seems the "+1" is not necessarily at all for a copied "char *" string to ...
20
votes
4
answers
2k
views
Why doesn't printing a Unicode character with wprintf work?
I made a small C program that should print an emoji:
#include <stdio.h>
#include <windows.h>
int main(void) {
SetConsoleOutputCP(CP_UTF8);
printf("\U0001F625\n"); // 😥
...
2
votes
0
answers
75
views
DS3234 incorrect value on STM32
I am trying to use a DS3234 with a STM32. (on STM32CubeIDE)
Is answer me with some value but for some reason,
Every value is divided by 2 except for the month.
Second are updated every two (real)...
2
votes
0
answers
112
views
How do I properly use Libwebsockets' JSON parser (LEJP)?
Trying to figure out how the built-in JSON parser in libwebsockets works. From my understanding of the documentation, you're supposed to call lejp_parse(), giving it a JSON-formatted string and a ...
2
votes
0
answers
76
views
How to stop Background Worker?
I have my extension and start background worker in the PG_init proc
BackgroundWorker worker;
/* set up common data for worker */
memset(&worker, 0, sizeof(worker));
snprintf(worker.bgw_name, ...
2
votes
1
answer
135
views
OSDev: Stuck at adding GDT
I've followed the book OS01 by Tuhdo, kind of made a simple bootloader, that loads the kernel. Then I tried to add some code to set up GDT, but I've witnessed unusual behavior in gdb.
Here I stopped ...
3
votes
3
answers
166
views
How to write Makefile for debugging only one header and source in c
The lib folder contains many *.h and *.c files, and all files are in development phrase and they contain many errors including syntax errors. So I want to write the Makefile to debug all libraries one ...