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
-4
votes
1answer
134 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
66 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 ...
5
votes
6answers
408 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
49 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
139 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
85 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
60 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
712 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
83 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
114 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
64 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 ...
-5
votes
4answers
322 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 ...
7
votes
2answers
394 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 call to ...
1
vote
5answers
401 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 ...
-2
votes
1answer
76 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
141 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
157 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
133 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
78 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
220 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
67 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
35 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
112 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
134 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
39 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
67 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
128 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
61 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
62 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
309 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 ...
5
votes
1answer
219 views

The case against path expressions in #include directives

I am preparing for a discussion with my fellow programmers which will be about their use of the C/C++ #include directive. The codebase which I have to retrofit to Automotive standards is using ...
0
votes
1answer
94 views

How should I provide generic typing and allocation for a collection library in C?

I am in the process of implementing a persistent collection in C, specifically, an immutable hash trie. In order to increase acceptance and reusability, I have identified the following key areas that ...
0
votes
1answer
67 views

A program design question: Good idea using HDFS in c for reading large data?

I have mainly three groups of CSV files (each file is divided into several small files): First group of CSV files have 600+ GB in total (MAYBE 200+ GB if in int, cause CSV calculates by char right?), ...
1
vote
1answer
65 views

Alternatives to service locator with opaque pointer in C

I have a project in which one module keeps the state of the target device (things like current command level, but mostly status registers caches). I'm aware that having a global public variable (...
-3
votes
3answers
141 views

If C isn't object oriented, then C is _____ oriented?

What type of programming is C. It is not object oriented, but what oriented is it? I googled it, and got no good answers.
4
votes
4answers
241 views

How is memory unsafety generated, found, exploited and fixed?

I'm not a low-level programmer, I mainly program in C# which is a managed language. Still, every now and then I read articles, news and patch notes about the most varied software talking about memory ...
23
votes
8answers
5k views

Detect manual changes to an autogenerated C header [closed]

I have a C header that is generated from a CSV file and a python script. The C header mainly contains a list of #define constants. I want to be able to detect manual changes to this header during ...
-2
votes
1answer
202 views

Why would you make a struct without typedef?

Since I cut my teeth on code with OO, I’m biased toward using structs as classes without methods. However, there’s probably a good reason that typedef isn’t the default behavior of struct. What is it?
2
votes
2answers
242 views

Loop complexity in C Vs Python

Just now I was reading a Python question on stack overflow, about clamping a list/array of results to be within a certain range. Once of the more simple answers suggested something like: ...
-3
votes
1answer
122 views

Is it possible to isolate C function from changes to its parameter type? [closed]

I would like to know if it is possible to code any function f that takes a structure S as a parameter while, in case we want to make drastic change to struct S, we can do it without touching a single ...
4
votes
5answers
754 views

How to deal with a lot of conditions in If statement in an elegant manner

Is there a more syntactically beautiful/simply better way to write the following (without major abstraction)?: if (usart_error.CRCError == true || usart_error.DMATransferError == true || ...
-1
votes
1answer
93 views

Better stdbool.h

How about instead of #define bool _Bool #define true 1 #define false 0 #define __bool_true_false_are_defined 1 We should have this: #define bool _Bool #define true (bool)1 #define false (bool)0 #...
1
vote
1answer
63 views

What are the limitations of WinSock2 sockets within threads?

So I've run into some strange behavior on an application i'm developing in C using the windows API. Im trying to implement a closed connection server-client interface. However, for whatever reason ...
0
votes
2answers
402 views

Logically, is there a reason why ++i++ can not be a valid expression?

I had to increment my integer twice in a loop, so I thought I would try and be clever: for (int i = 0; !sl.isEmpty(); ++i++) { ... } ++i++ however is not an assignable expression, at least in GCC. ...
0
votes
1answer
120 views

Architectural pattern for testable C code [closed]

I wrote a lot of software in C# and Python. I tried to make the overall architecture testable by using the "Clean Architecture" and Dependency Injection. This works well for C# (and python). Now I ...
2
votes
3answers
146 views

Declaring Multiple Variables of the Same Type within a Function's Parameters

We've started looking at functions, and our homework requires us to include some simple ones in our programming. As we've left it a little late in the semester to explore functions, we're well-used to ...
0
votes
0answers
83 views

Searching/Hashing Wikipedia - at each position for keys 1..31 long, the fastest way?

A C coder here. My wish is to find the best way to search words and phrases within the ever-growing English Wikipedia XML dump. As a first layer/step, hashing is the answer, yes? The problem is that ...
3
votes
4answers
415 views

Alternative to nested-if on single return functions

I'd like to see if there has been any precedent on alternatives to nested-ifs--particularly for error-code returns. My workplace requires one return per function, so I cannot early exit. Here is some ...
4
votes
3answers
283 views

How to adhere to the Open Closed principle in a procedural language like C

In Robert Martin's seminal 1996 article "The Open-Closed Principle" he presents an example in C which does not follow the principle (the DrawAllShapes() method is not closed for modification): enum ...
3
votes
1answer
76 views

Is a generic data structure customary for use in a self contained program, or can I duplicate source files?

I have a project that does some Dijkstra searches on a graph, I implemented a red-black tree and priority queue that I use for the nodes, however I also need the same data structures for other things ...

1
2 3 4 5
25