Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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

15
votes
2answers
3k views

Is converting a C++ method to a C function with a pointer argument an acceptable pattern?

I use C++ on ESP-32. When registering a timer I have to do this: timer_args.callback = reinterpret_cast<esp_timer_cb_t>(&SoundMixer::soundCallback); timer_args.arg = this; Here the timer ...
1
vote
1answer
116 views

Handling hardware dependency while unit testing

I am writing a driver for an IMU sensor using test driven development approach. Communication protocol of choice is SPI. Using CubeMX and STM32F415 processor, SPI interface is implemented in ...
-1
votes
1answer
165 views

Few unusual C/C++ declarations

I came across this Enum and Struct declarations in a project supposedly done by an expert. The declarations / definitions are little different than what im used to so far. enum EnumKeys { KEY_MENU ,...
1
vote
1answer
94 views

Find a string in list of strings

Background: I am writing an application for a small embedded device. There is a static list of strings: currently about 500 strings and string length is 12 characters on average. The list might ...
2
votes
1answer
83 views

How to abstract HAL in embedded test driven development?

Recently I've been reading into topic of test driven development and decided to give it a go with a sensor driver I need. Sensor uses SPI interface and I will implement this driver on STM32F415 ...
-4
votes
0answers
43 views

server processing tasks using c language and command line interface

One is required to perform the following tasks on words, including the following commands and functions 1. Doubling the word eg. double sara gives sarasara 2. Reverse the word eg. rev sar gives ...
4
votes
3answers
158 views

How to handle repetitive mallocs/frees in a DRY way in C

So I have a function which is like a constructor for my structure: MyStructure* CreateMyStructure(...) { MyStructure *my_structure; double *data; int *colind, *rowptrs; data = malloc(...
3
votes
1answer
178 views

Why do we need to specify the type of data a pointer will hold, if all pointers are the same [duplicate]

Why do we need to specify the type of the data whose address, a pointer will hold, if all pointers are the same. Since all pointers store addresses. Also, the amount of space a pointer will require in ...
1
vote
2answers
128 views

Using C coding conventions in C++ code [duplicate]

I'm working on a large codebase whose core modules are in C and extension modules are in C++. We have a coding convention for C code but I'm being told that we need to enforce the same coding ...
148
votes
7answers
22k views

Was the C programming language considered a low level language when it came out?

Currently C is considered a low level language, but back in the 70's was it considered low level? Was the term even in use then? Many popular higher level languages didn't exist until the mid 80's ...
2
votes
0answers
133 views

Embedded software architecture - What is the difference between DAL and HAL?

I'd like to know what the difference is between hardware abstraction layer (HAL) and data abstraction layer (DAL) when speaking about embedded software. I might have the abbreviations wrong though... ...
6
votes
1answer
231 views

Is it a good practice to redefine unavailable keywords as macros?

Is it a good practice to redefine unavailable keywords with macros? I use GCC 4.8 in one of my projects which isn't exactly C11 standard compatible. At least not the extent of 4.9. But there are some ...
2
votes
3answers
287 views

High level overview of how printf() works with Windows OS

I asked this question on an IRC channel, sadly I am going around in circles. I am aiming for a high level overview (but with some technical details if necessary) on how a function such as printf() ...
0
votes
0answers
89 views

Cycle accuracy through the use of a microtable for an 8 bit CPU emulation?

I'm in the process of writing a 8 bit cpu emulator and currently have a jump table for different opcodes. I want to move this over to be cycle accurate and was wondering what the best approach would ...
1
vote
1answer
92 views

Embedded Systems: Designing an API that monitors an address

This question was tossed as a starting point in a technical interview at a semi-conductor company. I guess there are no right ans - the purpose of this open ended question is to gauge the engineer's ...
0
votes
0answers
75 views

Conflicting opaque struct implementations as part of a C API

I am currently toying with the idea of designing a somewhat sophisticated C API. I have looked around existing APIs and found an interesting approach revolving around opaque structs. Specifically, I ...
3
votes
1answer
395 views

What tasks does a memory barrier enforces other than preventing the re-ordering of instructions?

I know that a memory barrier prevents the re-ordering of instruction from before to after and from after to before the memory barrier, for example if I have the following instructions: instruction 1 ...
-4
votes
1answer
186 views

TIOBE Index: why c++ is in 3rd place and C is having more land in the last year?

Searching for c++ ranking on the TIOBE index, I was stumped to see that C is in front of C++, and from 2017, C took a leap. Could someone explain why?
2
votes
1answer
128 views

How did graphics programming evolve over time? [closed]

There isn't a single blog/site out there that shows how graphics technologies evolved over time, how and why they became what they're now. If anyone can shed some light on it, it would be great. See, ...
1
vote
1answer
181 views

Difference between header files and interfaces

I wanted to know whether the header files in c and c++ have same function as that of interfaces used in Java? If not what is the difference between header file and interface?
-1
votes
1answer
142 views

Pointers and Values in C

I do a lot of work in various languages, most of which are scripting languages such as JavaScript, Shell Scripting, PHP and so on. But I do also work a lot with Java, which is closer to a more "real" ...
0
votes
2answers
187 views

copying of memory vs pointer to memory in real time systems

While working in a multi-threaded environment, then data sharing seems to be a good option to pass data between threads. While working with real time systems it is apparently advisable to go with ...
1
vote
1answer
164 views

Declaring functions using macros?

Is it generally encouraged or discouraged to create a pre-processor macro in C, that facilitates the creation of many functions with the same signature (differing only in name). For instance, instead ...
0
votes
4answers
295 views

Why does C provide both the comma operator and the semicolon to separate statements?

Both the comma operator and the semicolon can be used to separate statements. Let's consider this simple code: #include <stdio.h> void do_something(int*i) {(*i)++;} int main() { int i; ...
2
votes
2answers
182 views

API for data structure with indices, size_t vs int?

For a data structure with indices (e.g. an array list, a dynamic array, etc...), should the indices be of type size_t or int? Is there a clear reason to use one over the other? fooGetByIndex(struct ...
0
votes
0answers
36 views

First DSP project: Amplify digital audio input on Windows 7 on real-time

I want to learn bit about digital signal processing (DSP) with software. As the introduction to the field, I want to make simple real-time PC microphone amplifier, which amplifies the digital ...
4
votes
4answers
664 views

What is the correct way of adding third-party code into a C or C++ project?

I want to incorporate some open source libraries into my C project. This is the first time I do that, so I don't know what is the right or most common way of doing it. I see two possible paths I can ...
4
votes
4answers
411 views

Rely on compiler to remove unused code or #ifdef out?

I am working on a USB stack in C. This stack will be open source and used in various different projects. Various configuration options are available, which enable or disable large chunks of code and ...
1
vote
0answers
105 views

How could an fresher start doing changes in thousand lines code immediately after joining? [duplicate]

Well I am newly graduated and placed in a small scale project based company. When I joined , the boss (project head) gave me project code for understanding what work I will be doing hence forth. I ...
1
vote
1answer
126 views

Handling error in multiple state machines in embedded systems in C

I have few state machines which run "concurrently" in a super loop. do { state_one(); state_two(); state_three(); /* The point I want to deal with the error */ } while(1); Each of these ...
-3
votes
2answers
208 views

Why we use top== -1 for implementation of stack using simple array?

I am a newbie at data structures. I have read an implementation of a stack using a simple array. The algorithm for this implementation is presented below. Stack implementation in terms of an array ...
-1
votes
2answers
300 views

Should I use parenthesis around every operators?

The facts This is a very similar question to this one, but here I am talking about a more general case the MISRA-C3 Rule 5.0.2 or the SEI CERT C EXP00-C rule (more permissive). Within MISRA-C3 I ...
4
votes
1answer
392 views

Is CSS inspired from C? [closed]

Maybe I'm not the first to ask this, but I've searched up and down the stack and I am yet to get an answer to my question. I have learnt CSS, and I also have a basic idea of the C programming language....
1
vote
0answers
157 views

How does the BIOS detect the size of installed memory? [closed]

I'm writing a little toy operating system using a mix of C and Assembly (It's not meant to be good/fast, just meant to learn from). I know that I can issue an interrupt (I think it's INT 0x15) to ...
14
votes
4answers
1k views

How do you code something when you have no idea how it actually works? [closed]

I have recently learned C and want to start a project to solidify my knowledge. I've settled on making a very simple text editor, something like vim. The problem I face is that I genuinely have no ...
-2
votes
1answer
156 views

Is pointer holds a base address or it holds whole limits? [closed]

We have int i; which have 4 bytes lets have address from 1000 to 1004. if we declared a pointer int* p; p = &i; now is the pointer holds only 1000 or from 1000 to 1004? The pointer holds ...
2
votes
3answers
199 views

Are Instanced APIs a Problem in a C Interface?

So an Instanced API is one that behaves like an object. So for example: foo* GetInstancedAPI(); void MemFuncSetter(foo* fooThis, const int arg); int MemFuncGetter(const foo* fooThis) const; This is ...
0
votes
1answer
96 views

Type selection from a dispatcher table

I am trying to use a dispatch table to select a data type to cast something as and cannot figure out the syntax for this. g_cast_table[] = { {'h', short int} or {'h', "short int"} } ...
5
votes
1answer
96 views

Which registers should executable loader install before start a program?

For example, I have simple C program that only have main function that just returns 0. What registers should loader (Linux exec loader, I guess) install before start a program? I didn't find ...
1
vote
1answer
106 views

Some questions about implementing a preemptive scheduler in C: Context switching and execution time of the dispatcher

I am trying to implement a preemptive scheduler in C, but I have some understanding problems: When the scheduler is called by an interrupt, a context switch may occur. The context switch can only be ...
9
votes
3answers
573 views

When should new C projects target very old C standards (>20 years old, i.e. C89)?

Occasionally I see major, relatively new, open source C projects targeting very old C standards, typically C89. An example is systemd. These projects have intelligent people at the helm so they ...
0
votes
1answer
286 views

Computing the shortest path in a labyrinth

I'm currently trying to map how to make a good algorithm that won't have issues to find the shortest path. The labyrinth consists of an X and Y dimensions as input; However, the labyrinth will ...
3
votes
3answers
243 views

IOC container & accessing Implementation from the container

Background As mentioned in this article, Inversion of Control can be achieved through various mechanisms such as: Strategy design pattern, Service Locator pattern(SLP), Factory pattern, and ...
5
votes
3answers
189 views

Destruction of Linked List Nodes: Destroy Item too?

I'm writing a Linked List in C. list.h typedef struct list_struct * List; /* Defined in list.c */ List create_list(); void destroy_list(List list); void list_add(List list, void * item); void ...
3
votes
4answers
506 views

Should I assert the preconditions of functions in a public API?

I am writing a library for some data structures in C that will be used in embedded systems. I have had issues designing and coming up with a solid error handling plan. This API is only subject to ...
4
votes
4answers
384 views

Which is better, one central detailed comment, or several smaller ones?

To restate the question: Which is better, one central detailed comment, or several smaller "sprinkles"? Bear with me while I set up the scene: I've got this function for popping a value from a queue ...
3
votes
1answer
228 views

What motivates syntactic preference regarding pointer declaration in C/C++? [duplicate]

Both of the following are valid pointer declarations in C/C++: int *x; int* x; The former seems to be preferred by seasoned C/C++ programmers. I personally find the latter to be easier to understand ...
7
votes
3answers
432 views

How do you convey intent regarding pointers?

I've always used the tried-and-true "Document and Pray" approach when it comes to conveying the fact that a pointer result from a function (either as a return value or a reference parameter) should ...
1
vote
2answers
303 views

Increase processing use of Digital Signal Processor

I have a DSP (Digital Signal Processor) with a very well defined application, (this explication will be simplified) The DSP uses TDM (Time Division Multiplexer) frames to receive audio information, ...
3
votes
3answers
598 views

How useful is JNI in android?

In java/android we can call code written in the c/c++ language for execution speed advantage. I have heard of Ahead Of Time compilation which (as far as i know) compiles the entire application to ...