October 21, 2024
Chicago 12, Melborne City, USA

C++

C++ is a general-purpose programming language. Use this tag for questions about/utilizing C++. Do not also tag questions with [c] unless

C++

How can I scroll a part of the screen to see some options without the content on the sides moving? (in language C)

I am currently developing a cookie clicker-type game using Processing, and I’m facing a challenge with the user interface. In the section where I have multiple buttons for purchasing different structures, the design requires vertical scrolling to access all of the buttons. However, there are various elements on the right and left sides of the

Read More
C++

Access violation reading location in my c program

I am trying to write a C program which takes the values from an array, converts them to certain characters, then prints said characters. Here is my code: #include <stdio.h> #include <errno.h> int main() { /* * for 1 value in matrix, print # * for 0 value in matrix, don't print * every 3

Read More
C++

Problem with memcpy implementation in x86_64 assembly language

I have a task to implement memcpy function in x86_64 assembler with this signature: extern void* my_memcpy(void* dest, const void* src, uint32_t count); I wrote it: .intel_syntax noprefix .text .global my_memcpy my_memcpy: mov ecx, edx shr rcx, 3 rep movsq mov ecx, edx and ecx, 7 rep movsb - mov rax, rdi ret In my

Read More
C++

How can I get the destination MAC address of the node my macOS device is connected to in C?

So I’m implementing TCP sockets in C with raw sockets in order to further understand computer networking. I’m working on writing the ethernet header code, and I can get the source MAC address that’s burned onto my NIC with the getifaddrs, but I’m not sure how to get the destination MAC address. In FreeBSD which

Read More
C++

Win32 child process not flushing stdout until exit

I’m starting to write an LSP extension for vscode for my language in C (on windows). I’m having trouble with getting my extremely simple C program to flush stdout when spawned as a child process (vscode does this). When I run the same program directly from the command line, it works as expected. I have

Read More
C++

Why does a pointer to the first element of an array, after dereference, evaluates to the third element?

It dereferences to the third element when I’m trying to do it inside printf(), where I also try to dereference that pointer with post and pre-increment. Here’s my code: #include <stdio.h> int main() { int arr[4] = {1, 2, 3, 4}; int *ptr = &arr[0]; printf("ptr = %p, &arr[0] = %p\n", ptr, &arr); // same

Read More
C++

How to Initialize the tail pointer in a Doubly Linked List for it to not give Segmentation Fault

Now I have created a loop to make 25 nodes for the doubly linked list. By Initializing head pointer as NULL in the main function, now the forward_traversing and show_first functions do work as intended. But the tail value cannot by initialized NULL and I don’t know what to assign it or to change in

Read More
C++

Forked process that waits on a response listener not outputting to screen after response

I have a C program that forks a process and waits for a success message before continuing with the main program. If the main program receives an error message then the fork will re-attempt itself and continue to do so until a success message is received. This portion of the code works as expected. What

Read More
C++

Signal queuing in C

[C language]\ Hello there! I’m trying to do a simple IPC between two files ".c" but I’m facing some unexpected output. I’m compiling the server file, nothing wrong, the PID is clearly printed. I’m compiling the client with PID of the server and a string of 100 chars -> usleep(3000) -> expected output -> usleep(100)

Read More
C++

Warning: Iteration 1 Invokes Undefined Behavior

I’m not seeing the issue. typedef struct GeneralSensorParams_ { uint8_t threshold; uint8_t negativeThreshold; uint8_t baselineThreshold; } GeneralSensorParams; typedef _ALIGNED_(64) struct GeneralNVParams_ { uint32_t checksumOffset; GeneralSystemParams system; PerSensorBitFields bitfields[10]; GeneralSensorParams sensor[1]; uint8_t checksum; } GeneralNVParams; GeneralNVParams const* G_pGeneralNVParams = NULL; int main (void) { for (uint8_t i = 0; i < 1; i++) { if (tempThreshold[i]

Read More