Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
1 vote
1 answer
28 views

Can't put values together into struct that is initiated by pointer and malloc [duplicate]

Just a simple struct called person, inside I need to store name and age. I'm trying to dynamically allocate memory for my struct. Without using pointer: #include <stdio.h> #include <stdlib.h&...
cutelittlebunny's user avatar
1 vote
1 answer
72 views

In structs, why is initializing to 0 not allowed but initializing to 1 is valid code

#include <stdio.h> struct temp{ unsigned int zero_bit : 1; unsigned int first_bit : 1; }; // struct temp_1{ // unsigned int zero_bit : 0; // unsigned int ...
WorkerBee's user avatar
1 vote
1 answer
149 views

Can't understand this C syntax. Designated initialization of an array of structs?

Trying to learn the nuances of C, though I was doing well until I found this: #define SOKOL_IMPL #define SOKOL_GLES3 #include "sokol_gfx.h" #include "sokol_log.h" #include "...
Matheus de Moraes Peixoto's user avatar
0 votes
1 answer
71 views

C code for solving a 15-puzzle gives a segmentation fault when it tries to show the paths for each update to the puzzle

I have a code that is supposed to show the paths in solving a 15-puzzle after showing the initial state and goal state. However, while it does show the initial state and goal state, it gives a ...
Sebastian Llaurador's user avatar
1 vote
1 answer
111 views

Why is it considered okay to use structs to represent MMIO registers in embedded system firmware, but not bit fields?

In embedded system firmware, it's common to represent multiple memory-mapped registers of a peripheral using a struct, under the assumption that compiler's code generation will follow a particular ...
比尔盖子's user avatar
  • 3,337
1 vote
4 answers
126 views

Using free on nested structs makes program crash

I was recently exploring ll the oop features of C, when i came to this issue. I want to create a game engine with C, so i use nested structs to organize ewerything. But when freeing the memory, the ...
TheTrueJerome's user avatar
0 votes
1 answer
58 views

Invalid initializer error with anonymous structs

I have this code here: Void() aba () { } #define std_Dynamic_Array(T) struct{Int32() count; Int32() capacity; T* memory; } Void() no_body_func (Int32() b); Int32() test_func (Int32()*** a) { } Int32() ...
kamkow1's user avatar
  • 499
1 vote
2 answers
92 views

Error with operations on the elements in shared memory C

I made this code that inserts a structure into shared memory. I made debug prints to try to figure out where the processes were stopping and why there was an error. Apparently by doing operations on ...
MiusiZ's user avatar
  • 203
1 vote
0 answers
91 views

Problem with malloc and shared memory in C

I am trying to put shared_pid_data in shared memory. I need to have a dynamic array, so I use malloc, I also tried using calloc getting the same result. The problem I am encountering is that the data ...
MiusiZ's user avatar
  • 203
-1 votes
2 answers
74 views

Is it possible to implement a recursive POD wrapper in C++?

I have a class to wrap POD struct types, but I'm having trouble when a POD struct has another POD inside, because my wrapper class only stores the POD as it is, using composition. #include <utility&...
edugomez102's user avatar
1 vote
0 answers
63 views

Handling Large Text Files with Pipes in C: Minimizing and Debugging a Word Frequency Counter

This program is a minimized version of a larger project that processes text files to generate CSV output with word frequencies. The full version works well for small to medium-sized files but ...
iPc's user avatar
  • 53
0 votes
0 answers
57 views

Italian Text Frequency Analyzer: Handling Special Characters and Accents

The program works well overall; however, it encounters an issue when it processes accented words. When the program encounters words with accented characters, it stops functioning correctly. The exact ...
iPc's user avatar
  • 53
0 votes
2 answers
91 views

How to test a C pointer for whether it points to a struct

I have a linked list structure struct node { int data; node next; } and a function struct node *insert_sorted (struct node *nodes, int d) { // todo } I need to implement this so that, given a ...
Addem's user avatar
  • 3,823
2 votes
1 answer
184 views

C++: C union struct has to be initialized with double "{"

Why does my C struct my_type_t has to be initialized using double { in C++ but one { in C is enough? #include <iostream> #include "types.h" int main() { my_type_t t = { { .bla = ...
binaryBigInt's user avatar
  • 1,662
2 votes
1 answer
69 views

does windows networking code break the strict aliasing rules?

As I was told here: can you typecast an int into 4 chars using structs?, typecasting a struct into another struct pointer is against the "strict aliasing rules". But I think that in C ...
bangingmyheadontable's user avatar

15 30 50 per page
1
2 3 4 5
977