Questions tagged [c]

C is a general-purpose computer programming language used for operating systems, games and other high performance work.

Filter by
Sorted by
Tagged with
0
votes
0answers
30 views

How do I break down my components and files in C

I've been designing an event processor for state machines in C and I'm trying to figure out what's the best way to break down my components in simpler and smaller *.h and *.c files. Specifically I'm ...
0
votes
0answers
41 views

How to best design this communication module/library?

Introduction A customer of ours has embedded products with sensors and actuators. Now they would like to connect this device to the cloud so they can remotely monitor and configure it. It should ...
-2
votes
1answer
79 views

What is the time complexity of this algorithm

This code is from https://www.geeksforgeeks.org/segregate-even-and-odd-numbers/ It takes an array of numbers & segregates them in place without bothering about the order. void segregateEvenOdd(int ...
-4
votes
1answer
112 views

How do I manage multiple nested for-loops without using multiple variables?

If I have code that looks like this: int i; void functionA (){ for (i=0; i<10; i++){ functionB(); } } void functionB (){ for (i=0; i<20; i++){ doSomething(); } } ...
-3
votes
0answers
83 views

How to decrypt a file to memory and run it from memory using c, c++, or python?

I have experience with the basics of encryption and decryption and handling files stored on the filesystem using c, c++, and python. But one curiosity I've recently encountered is how someone might ...
3
votes
4answers
278 views

Elegant way to check return of getXY() for multiple values in conditional check

When I want to execute some code under the condition that a variable has one of two (or more) values I can use the OR operator: if (var == x || var == y) { DoSomething(); } But I'm not sure ...
-2
votes
1answer
57 views

What should I use to graphically represent an object's position on a fixed path using python(preferred)?

Consider 2 roads merging into one(This map is supposed to remain fixed). The program will not generate this map. The program will read this map and plot positions on it on its own. The python program ...
-1
votes
2answers
103 views

What design/component principle did I apply? How can I further improve it?

I recently refactored a program for code feasibility and maintainability; however, I am totally unaware of what software principle I did implement. I just followed my feeling. The purpose for this ...
2
votes
5answers
533 views

Do all threads share the same instance of a heap variable, or have different instances of a heap variable? [closed]

Computer Systems: a Programmer's Perspective says: 12.4.2 Mapping Variables to Memory Variables in threaded C programs are mapped to virtual memory according to their storage classes: Global ...
2
votes
3answers
125 views

Use of globals in stack-based virtual machine implementation

I'm implementing a stack-based virtual machine in C. The following variables are used by pretty much every function: memory array various pointers to memory offsets program counter stack stack ...
0
votes
2answers
151 views

Cases of memory management where it is reasonable to separate program into several execs

I have 5000+ strings pet-project for CLI and it can do some optional calculations and can output results to CLI or/and to file. Some new modules don't work. Now I catch with GDB some strange segfaults ...
-2
votes
1answer
59 views

How should functions that keep state across multiple invocations be made safe?

In Computer Systems: a Programmer's Perspective, 12.7.1 Thread Safety When we program with threads, we must be careful to write functions that have a property called thread safety. A function is said ...
-4
votes
4answers
321 views

Since `strcpy`, `strcat`, and `sprintf` are dangerous, what shall we use in stead of them?

In Computer Systems: a Programmer's Perspective, Unfortunately, a number of commonly used library functions, including strcpy, strcat, and sprintf, have the property that they can generate a byte ...
0
votes
2answers
140 views

What is a “function returning type” in C?

C11 standard says 6.3.2.1 Lvalues, arrays, and function designators A function designator is an expression that has function type. Except when it is the operand of the sizeof operator, 65)...
2
votes
1answer
101 views

Ask for suggestion: data type for parsing stringified fractional numbers

I am the author of a C library for parsing INI files. So far I have delegated the task of parsing values as numbers to the standard atoi() family of functions. However I think time has come that I ...
2
votes
2answers
136 views

Are bitwise operators in C used both for bit operations and for operations for integer or some C types?

In C, Bitwise logical operators &, |, ^ is used for selecting bits in a word. Bitwise shifting operators >> and << can be used for implementing multiplication and division between ...
-3
votes
1answer
49 views

Does this alignment of structure objects apply only to structure objects being used as elements of an array?

In Computer Systems: a Programmer's Perspective, In addition, the compiler may need to add padding to the end of the structure so that each element in an array of structures will satisfy its ...
-4
votes
2answers
94 views

IO stream interface in C

When writing a library (eg. for dealing with JPEG or PNG files), the first thing library author needs to provide is an abstraction over FILE* (to allow also reading from plain memory, pipe, socket, ...
0
votes
2answers
309 views

Why are some languages called platform dependent if I can always share the source code?

I was reading about erlang when I read that it is platform-independent, using BEAM as the VM, now I understand that a VM compiles the byte code to machine code and this makes that language machine-...
-3
votes
1answer
150 views

Data structures or coding styles in C++ for avoiding long elseif chain when parsing?

Lately I have created some small parsers of data. My initial code structure // more cases here ... else if(!strcmp(X,"somekey")){ // Parse according to "somekey" behavior. } // ...
-4
votes
1answer
159 views

Do these two design philosophy conflict with each other?

With few years of C programming, I noticed there are two major types of design choices for data organization. I offer an analogy below. First: height folder: Andy.txt, Bruce.txt, Chris.txt and Tina....
1
vote
1answer
95 views

What is the name of this kind of (intra-process, inter-thread, queue-based) event system?

Context Espressif's embedded development libraries for the ESP32 microcontroller contain an event system based on FreeRTOS. The event system handles connectivity, interrupts and other IO activity, but ...
6
votes
6answers
532 views

How is design using C different from C++?

A employer is looking for C programmers, and I'm told they say that ... Good C design isn't the same as good C++ design ... and so they're looking for candidates experienced with C and not only C++. ...
-2
votes
1answer
54 views

Adding samples from wav files without causing integer overflow

Recently, I've been writing a wav writer in C. For this question of mine, Let's consider two wav files that we'll be combining the samples; both are s16le mono wav files to be simple. The first idea ...
0
votes
3answers
151 views

What goes into a computer deciding how many memory locations to assign for specific data types in C?

I have learned file memory management and some very simple CPU assembly for manual memory manipulation. Still, I feel like there is a gap in my knowledge when it comes to modern, complex computers, ...
2
votes
1answer
93 views

What is the design of libraries like cairo and OpenGL called?

I'm not a software engineer, so sorry if the question is elementary. Usually, functions provided by libraries written in C receive a handle from the calling program. This handle directly (if it's a ...
1
vote
1answer
91 views

How to check data has been received correctly with CRC - much confusion here

I am trying to process some serial data (sent over UART). Its coming from a radio controlled receiver, is 27 bytes long. The last 2 bytes of this are a 16bit CRC check according to the spec. The ...
7
votes
5answers
835 views

Why are people coding “C-style C++”?

In discussions about whether to cast the result of malloc or not when coding C, one common argument is that if you cast the result then you can compile your C code with a C++ compiler. Why would one ...
-5
votes
2answers
100 views

Current industry standard with regards to C macros [closed]

I have read from several authors that macros in C should be avoided whenever possible, and use inline functions instead. It's true that inline only 'requests' the compiler to replace the function call ...
-4
votes
2answers
207 views

Malloc vs variable length array?

In general, should I use variable length arrays or malloc? In my specific case I am processing files of very short to very large sizes. Also if I compile on version MacOS 10.15, and then run on 10.13, ...
-4
votes
1answer
73 views

Using only the Cache not the DRAM in a Program (USB to Ethernet) [closed]

I am reading some data from USB, do some packet processing and then send the result to the Ethernet port. The USB ports are connected to an onboard USB Hub where it communicates with the ...
-4
votes
4answers
434 views

Why are magic numbers bad practice?

Why are magic NUMBERS considered bad practice? For example: memcpy(ResourcesDir+GameDirLen, "/Resources", 11); What is wrong with the 11? Why are magical numbers so bad? Please, my question ...
10
votes
2answers
551 views

Why would you ever use `malloc(0)`?

While reading an answer here, I saw this code: char ** v = malloc(0); while ((r = strtok(s, " ")) != NULL) { char ** vv = realloc(v, (n+1)*sizeof(*vv)); The thing that bugged me was the ...
1
vote
5answers
935 views

Is using 64 bit integers (long long) faster than less bits ones?

I read in the book "Game Engine Architecture" by Jason Gregory that: "It’s possible to access data items that are narrower than the width of a machine’s data bus, but it’s typically more costly than ...
-1
votes
1answer
78 views

Are jagged arrays lvalue or not?

When I was study lvalue i see that C expression can be lvalue if a subscript ([]) expression that does not evaluate to an array. (from https://docs.microsoft.com/en-us/cpp/c-language/l-value-and-...
1
vote
1answer
300 views

How do I implement Dependency Inversion in C?

I'm a firmware developer and I'm interested in applying the SOLID practice in low level programming especially in Hardware Abstraction Layers in ARM microcontrollers. Every example I come across on ...
-2
votes
2answers
162 views

What is the correct use of -> operator when working with pointers?

I'm pretty new with C so I have encountered many doubts with pointers. I've already search a lot about this but there are some things that still are not clear for me, and I also think this will help ...
0
votes
1answer
135 views

Which is better? One line per action or shorter lines? [closed]

The first alternative can result in lines that are too long, and so reduced readability in some web browsing. The second one can result in a better web readability, but might annoy command line ...
1
vote
1answer
93 views

Modular programming with C: Separate device logic from communication protocol logic

I have no experience with C (only C++ and higher level languages). Right now I have tried and failed to find general guidelines on how to write good C code in a way that allows to separate the ...
5
votes
2answers
235 views

Merits of passing function arguments through a single struct

A coworker has started advocating for a style for our user-facing APIs where every function takes a single struct parameter containing all the real parameters. That is, instead of: void fn(int foo, ...
2
votes
1answer
79 views

Publisher-Subscriber architecture with central registry

Problem description Publisher-Subscriber architecture with a central registry where agents can either promote their capabilities or search for a given capability. The project must be developed with ...
1
vote
0answers
44 views

FreeRTOS based application architecture

I am going to use the FreeRTOS on my hardware platform. My plan is to model individual tasks as C structs containing task execution period, task priority, task stack size, task name and maybe another ...
-4
votes
2answers
117 views

How to exploit efficiency of C? [closed]

I want to write a program that performs heavy computations and I want it to be as fast as possible, so I choose C to be the language. Nevertheless, I was told that in spite of its simplicity and high ...
2
votes
2answers
144 views

sizeof(a)/sizeof(a[0]) vs sizeof(a)/sizeof(t) where t is type in C from K.N.King

I'm trying to understand why sizeof(a)/sizeof(t) is inferior for getting the length of an array to sizeof(a)/sizeof(a[0]) if just as it's possible to have different types, my elements could also be of ...
0
votes
1answer
62 views

How to go from Simulink to embedded fixed-point DSP processor?

A library of audio algorithms is modeled, tested and verified in Simulink (graphical block diagramming tool). It needs to go from this existing Simulink models down to a multiple embedded platforms (...
-3
votes
1answer
71 views

Methods for reliably benchmarking own program's run time

I'm writing a basic password cracker in C as an introduction to multithreaded programming. I've implemented this already using a 'parallelization' approach that spins up a set number of threads and ...
-2
votes
2answers
133 views

Is it possible to write unit tests for embedded systems with no prior embedded programming knowledge?

I have this question for a long time that is it possible for someone with no prior embedded systems programming experience to write unit tests? I have good knowledge of other languages like JAVA, ...
-4
votes
1answer
64 views

Best practices when interfacing Python and C code

I have a piece of code that I developed in an academic context for which I would like to build a nice frontend. My approach to coding has been very academic to this point (read: I made stuff up as I ...
-1
votes
1answer
74 views

How does a robust http server handle requests?

I have written many http(s) servers in Node.js and just take for granted that I can receive many requests and all IO operations are async. However, now I would like to try and implement an HTTP server ...
7
votes
1answer
372 views

Why is it difficult to create a truly portable garbage collector for C?

When reading the Python docs for writing C extensions, one can find the following text in the part about CPython's garbage collection strategy (emphasis mine): ... The disadvantage [of automatic ...

1
2 3 4 5
25