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
-2
votes
0answers
14 views

Case in Fastled sketch combining the previous case [closed]

I've combined code from two Arduino sketches. The sketch is built on the Fastled library that does not show errors when compiled, but in practice combines 2 different effects when displayed on my ...
2
votes
2answers
103 views

Strategy for offering a library both a single-header and as a header + compiled implementation

I am maintaining a FOSS library which, for the sake of discussion, consists of a small .h file and a larger .c file (plus build-related files, see below) I've been requested to offer this library as a ...
-4
votes
1answer
51 views

Is there a way to use a third party Python or C API through C#? [closed]

I will receive a hardware which will have native Python API to communicate through USB. The device will continuously send image data. The vendor only supports Python and C APIs to communicate with the ...
-2
votes
2answers
130 views

Is there any other reason to Null-terminate a string besides to find out the length of the string? [closed]

I have looked at the source code of some standard C functions and wondered what the reason is for null-terminating a string other than to find out its length. e.g. The strlcat() function which is ...
24
votes
8answers
6k views

Should I assume data passed to my function is accurate?

Assuming I have the following struct (just an example) struct string{ int len; char*str; } And I have the function int init_str(struct string*s, int len); which will perform s->len=len; s-...
0
votes
1answer
90 views

Implement Dependency Inversion in C with UML diagram

As per Robert C. Martin in Clean Architecture, he gives a simple UML diagram to illustrate Dependency Inversion. To put it simply, HL1 initially referred to ML1 without interface to invoke F() ...
0
votes
5answers
75 views

best practice for error handling between PAM_SUCCESS and PAM_AUTH_ERR macros

We have two exit code code PAM_SUCCESS(0), PAM_AUTH_ERR(7). If we wanna return 0 or 7 when we compared password with our password in following code which code is better that this code ? if (strcmp (...
2
votes
1answer
74 views

How could Vulkan pNext design be implemented in a "safer" way?

Vulkan introduces a member .pNext of type void* in all its core structs allowing to create handles. This member purpose is to allow to extend the structure by passing a pointer another one. This is ...
2
votes
3answers
161 views

What methods are available to implement feature flags or "loadouts" for C++ projects?

I'm looking for a system to be able to configure my C++ project to compile some sections of codes and not others depending on what target hardware I'm compiling for. The area of development is ...
2
votes
1answer
188 views

How to properly delete nodes in a linked list?

I'm doing this homework exercise with simple linked lists in C with nodes having the following structure: typedef struct lista { int num; struct lista * next; } nodo; So the exercise asks us ...
-1
votes
1answer
154 views

How can I initialize an empty binary search tree in C?

I am trying to implement a Binary Search Tree in C as a learning exercise. I have the following struct that represents a node. typedef struct BSTNode { int data; struct BSTNode *parent; ...
0
votes
0answers
73 views

Designing a logic to receive ACK for every message sent in a non-blocking way

This is more of a design/architecture question: I have got a timer based scheduler which informs the client of what and when to run next on its end. For which, I created a priority queue based timer ...
1
vote
3answers
231 views

Debug statements in production quality code?

Would anyone here recommend using debug statements such as the following in production quality code? I think these are personally one of the easiest to include or exclude, but they make the code hard ...
0
votes
1answer
87 views

Help architect a timer-based scheduler

I am writing a timer-based scheduler to accomplish the task of informing a certain process of what to do and when. The Idea: Inform an X process of certain requests to perform at timed-intervals. So ...
0
votes
1answer
130 views

Opaque objects on the stack / in structs

I have a collection of opaque objects and related functions API. Such objects are typically created on the heap, but that involves a non-trivial amount of overhead. And when aggregate together, that ...
-5
votes
3answers
547 views

Could H correctly decide that P never halts?

a practical, answerable problem that is unique to software development Could H be adapted to correctly decide that P never halts? #include <stdint.h> #include <stdio.h> typedef int (*ptr)...
5
votes
2answers
395 views

Is there a standard error handling design pattern for C?

I'm working on a large C application that I've divided into sub-libraries (e.g. networking, message handling, message building, etc.) I've converged onto a pattern where functions are only allowed to ...
0
votes
2answers
122 views

Low level C driver API

Recently I had my first experience writing a wrapper around FTD2XX driver for a desktop tool that communicates with an embedded device. The library provided some common device specific functionality ...
0
votes
2answers
93 views

Data structure for graphs and vectors in C

I'd like to design an implementation for graphs in C. I'm wondering what the most efficient approach in terms of both computational power and memory consumption would be. I've looked at various open-...
2
votes
2answers
303 views

C99: Alternative to "static" variable declaration?

By coincidence I stumbled over "The New C Standard" from Derek M. Jones, where he comments this sentence from the C99 standard regarding "storage duration of objects": There are ...
0
votes
2answers
471 views

How can Python, a language that supports Object Oriented Programming, be implemented in C, which is not an Object Oriented Programming language?

To my understanding, C does not have the concept of objects, then how can Python be implemented in C to support something that C can not? How is the concept of "Object" modeled in C? What is ...
2
votes
1answer
111 views

How should a bytecode VM call external C functions?

I am trying to implement a basic bytecode VM, which I plan to target with a compiler. How can I implement the ability to call external C functions using the bytecode, i.e., call arbitrary functions in ...
1
vote
2answers
419 views

C Const Safety with Struct Data Pointers

In our codebase, having precise management of memory, data was being passed around like so: typedef struct { size_t const sz_size; size_t sz_len; int32_t * const restrict pData; } S_ARR_T; ...
0
votes
3answers
80 views

Designing this module to support exchangeable drivers

We have a battery manager implementation which uses a fuel gauge driver and a charger driver. Currently both of these drivers are hard-references to the fuel gauge and charger driver we currently ...
0
votes
3answers
98 views

Is it better (or preferred) to initialize allocate and free structures used by a thread, "inside the thread"

Let's say we are building a threaded program in C, for example a message queue system where a thread is spawned to manage one end of the queue, and (re)connect sockets. This can roughly be set up in ...
0
votes
1answer
109 views

What design pattern (if so) did I apply? How can I further improve it?

Suppose I have a program.c that needs element_123 to do some operations, and element_123 can be accessed by including agent.h /*program.c*/ #include "agent.h" uint32_t element_123 = 0; ...
2
votes
4answers
192 views

Naming convention for functions that mutate arguments vs creating a new object

Take the following signature BigInt* addBigInt(BigInt* arg1, BigInt* arg2); Traditionally, the safest way to implement this function would be for it not mutate the arguments, and would necessarily ...
-1
votes
1answer
164 views

Should all structures be ADTs?

Is there any specific category an ADT must be in? I'm struggling to find out how best to represent objects in the program for example: As a record: struct Person { int age }; Or as an ADT: struct ...
1
vote
3answers
209 views

Unifying and modularizing the while / do feature set in c

disclaimer: I'm a university student who's one-year-new to programming. Please don't slaughter me in your responses as I am still a human being I have an idea that I want some feedback on. I am ...
2
votes
1answer
94 views

Methods for remote display of and embedded FreeRTOS devices display

I have a device that has a NXP MK66FN1M arm core processor with a black and white display. This device is running FreeRTOS with serial, usb, keypad, display, external FeRAM, wifi, and ethernet. What ...
3
votes
4answers
255 views

Should functions depend on other functions?

Suppose I have a function to log error messages printError(). Suppose I have another function which might throw an error, doSomething(). Should doSomething() implement its own error logging or depend ...
0
votes
1answer
79 views

Custom datatype and their constructors - should you clone, or just copy?

Suppose we have the following C snippet, implementing a tree data structure: typedef struct node { char* data; struct node** children; unsigned int num_children; } node; Then we could ...
-1
votes
3answers
241 views

Is it possible to solve this synchronization problem using mutex and conditional variables?

I am trying to solve this synchronization problem in C to practice for my lectures of Operating Systems where we use POSIX and Linux. I've been trying for days to find an approach to this problem with ...
0
votes
0answers
43 views

Sharing values among enums

I'm designing a state machine framework. (Yes, I know they already exist, but bear with me...) My "standard state machine" always defines four states: typedef enum { STD_SM_STATE_INIT, ...
-2
votes
1answer
100 views

How to manually delete a std::vector in c++? [closed]

I have following code snippet void func(int row,int n,std::vector<int>& buffer){ if(row>n){ return; } std::vector<int> new_buffer; for(int elm : buffer){ ...
1
vote
1answer
133 views

How to separate public and private headers when internal data structures are private?

When developing a shared library in C, it is common to separate the "public" headers from the "private" headers. The public headers contain all the functions and types that are ...
-4
votes
1answer
148 views

Understanding C after getting used to scripting languages

I use python and javascript in my daily workflow. I am really excited about understanding c as I am drawn towards contributing to projects that are written in the language but even after weeks of ...
0
votes
2answers
135 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
52 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
93 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 ...
-5
votes
1answer
256 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
4answers
294 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
69 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
127 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
2k 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 ...
4
votes
4answers
186 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
162 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
103 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
1k 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
178 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)...

1
2 3 4 5
26