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

Priority Issues – Use LEX to write regular expressions to match strings of specific patterns

I try to write regular definitions to display the line of string for the following using LEX. a.Match any string starting with d, and ending with t b. Matches the string def c.Match one or more occurrences ab concatenated d. Match any string of one or more characters that do not include upper case A-Z

Read More
C#

Failed to mount /proc after clone with CLONE_NEWUSER

I’m trying to mount /proc and /dev after pivot_root, but it’s failed if the child process is create with CLONE_NEWUSER. Refer to the following section for the code. After removed CLONE_NEWUSER when clone, everthing works. #define _GNU_SOURCE #include <err.h> #include <limits.h> #include <sched.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <sys/mman.h> #include <sys/mount.h> #include <sys/stat.h>

Read More
C#

Is it ok to call HAL_TIM_PWM_Start on runtime with STM32F091?

I have an initialization block of code that initializes the timer 2 on an STM32F091. Inside this block, there’s a section that needs to run accordingly to a certain variable (type_b ) like: static void MX_TIM2_Init(void) { ... some code ... htim2.Init.Prescaler = 0;//400; htim2.Init.CounterMode = TIM_COUNTERMODE_UP; htim2.Init.Period = 60-1;//1000; ... some other code ...

Read More
C#

How to divide a canvas into my squares number

I have a 5504 x 1504 canvas , I looking for algorithm to find how many squares can spawn in canvas , the number of spawn square is different , for example for total 200 spawn , the algorithm should be calculate what is the size of square for 200 spawn and of course if

Read More
C#

How to use unions in C for pseudo-polymorphism

Consider a data structure to describe blocks of a matrix in C: // Matrix block typedef struct { union { int i; double d; } *a; // pointer to first element in matrix block int k; // block index int p; // no. of block rows int q; // no. of block columns int m;

Read More
C#

Nested if statement in C not executing inner if

Struggling (newbie) with a nested if in C, probably doing something stupid. Basically a switch down tester which determines whether just down for a second or longer. void SwitchTest(void) { __delay_ms(3000); // LEDCOM = LED_ON; // Connect Bar Common LED1 = LED_OFF; LED2 = LED_OFF; LED3 = LED_OFF; LED4 = LED_OFF; LED5 = LED_OFF; if

Read More