October 22, 2024
Chicago 12, Melborne City, USA
C#

The scanf function uses '%c' to accept input, but can perform string input

How to understand the running process of the following code. void scan(void){ char item; scanf("%c",&item); if(item == '#'){ printf("\n"); return; } printf("%c",item); scan(); } Why can I input strings into the console, and scanf will not be executed again in the recursion, but each character will be read automatically instead? You need to sign in

Read More
C#

Problem accesing global variables in main.c through .S assembler source file (MPLABxIDE)

My project consists in: Using a 4 digit 7-segment display to show certain numbers, representing the amount of cash stored in a moneybox. I am using both .c and .S files. To rotate between the 4 digits I use a 4ms TIMER0 interrupt, whose ISR calls the Assembly function. Apart from that interrupt, I am

Read More
C#

First call to rand after calling srand doesn't look random at all

I’m getting strange behavior out of the rand() function in C. The result of the first call to rand() after srand() looks very predictable and un-random. I tried both with the seed from 0 to 10, and using the system time as a seed and sleeping 1 sec after each call to srand, produced similar

Read More
C#

Packing multiple writes into single TCP packet

I have a sequence of send() calls to write bytes to a TCP socket. Is it possible to force the socket to only send TCP packets when they are either full (exceeding the MTU) or I explicitly indicate that I’m done sequentially calling send()? Specifically, I have some code like: // these are user-provided, I

Read More
C#

Understanding virtual memory via background jobs

Understanding virtual memory in Operating Systems: Concepts and Implementation Unexpected behavior when running multiple instances of a memory allocation program. I’m learning about operating systems and following the OSTEP (Operating Systems: Three Easy Pieces) textbook. I’m trying to understand memory virtualization by running multiple instances of a program simultaneously. Here’s the code I’m working with:

Read More
C#

Reading PNG data regarding

I am trying to read PNG data with libpng, but I am not able to figure out the last step. I am trying to read png pixel data. Here is what I came up with #include <png.h> #include <pngconf.h> #include <stdio.h> #define BYTES_TO_CHECK 8 // checks the file and returns the file pointer FILE *check_png(char

Read More
C#

STM32 FDCAN filters not filtering anything

The problem I am unable to get the HAL CAN filters to filter anything. I have FDCAN working perfectly on my STM32H723VGT6 uController. I would like to now implement CAN filters, but when I configure the FDCAN filter, nothing is filtered, all Rx messages still trigger the RxFIFI0 callback. What I have tried: // Can

Read More
C#

Linker Fails To Resolve External Pointer

I am trying to compile the following files using gcc (arm-linux-musleabi-gcc (GCC) 9.4.0), but the reference to json_start does not get fixed up correctly and incorrectly ends up as an offset rather than a pc relative access (ie. 0x4762 instead of 0x5114762). The idea is that the json contents get binned into the binary. Ideally

Read More
C#

How do I successfully test this trivial buffer overflow written in C?

I am trying to test this example from StackOverflow (how-can-i-invoke-buffer-overflow), but I am not having success. I also asked for clarification two weeks ago, directly on the post (through a comment) but there was still no answer (perhaps too old, 2010). I am asking for a parsimoniously way of make this work: compiler options, operating

Read More
C#

Is it safe to pass a uint32_t to a function which defines the input type as uint64_t?

Pass a uint32_t to a function that requires uint64_t: You can do this, and all compilers I know accept it, even in strict modes. Is it explicitly allowed by the standard? Is it safe? What does MISRA-C say about this? void MyFunction(uint64_t arg) {} int main(void) { uint32_t xyz = 1u; MyFunction(xyz); } You need

Read More