New answers tagged

1

but aren't designed to be extended. I'm not quite sure how much you researched the event libraries you mentioned, but they do support creating custom events. For example, with libevent, when creating an event structure, you can pass in -1 to the file descriptor to create an event that can only be triggered manually and not by IO: If events contains one of ...


0

C's toolkit is much smaller than C++'s. With C, you don't get polymorphism run time type determination structured exception handling built-in data structures (containers) and a host of other useful features. Well-designed C code won't look or behave anything like well-designed C++ code because it just doesn't have the features C++ does. For example, if ...


5

The differences between C and C++ are so large these days that they are two different languages that require differences in how designs are expressed in those languages. C offers one paradigm, procedural, for writing code where as C++ is multi-paradigm allowing a larger implementation vocabulary for implementing a design. You can use a procedural paradigm or ...


3

Look at this Linux kernel code, for an example of well-designed, idiomatic C code. Notice: There is hardly any direct memory allocation or freeing happening in this file. People who are good at object-oriented design but not C design often have malloc and free all over the place because they are not accustomed to minimizing that in their design. These ...


1

"As ever it was since 'C++' was a 'C' compiler preprocessor," the fundamental idea is simply "to avoid pointlessness." 🤠 The "C" programming language was – just as in the late 1970's it was intended to be – "an enormous(!) step forward from [machine-specific ...] assembly language." (And it still proves its worth: the ...


1

This is a challenging question, because the design may be influenced by the language but not necessarily: there are a lot of examples of C++ code that is written as if it was C with some syntactic sugar for type management. Everyday on SO you find students posting C++ code from their teacher that is just C with classes and not at all in the spirit of modern ...


0

Just a guess but in the context of an embedded system a difference might be in memory allocation/deallocation. Language support for polymorphism is nice but can easily be simulated when you need it -- e.g. a pluggable device driver can expose an array of function pointers, which behaves like a vtable implementing an abstract interface. Apart from ...


1

There is no single correct way to add audio samples together. The samples in a (uncompressed) WAV file represent the amplitude of the sound signal at the time the sample was taken. As the top-top amplitude of the signal is also a representation for how loud the sound is, halving all the sample values will also have an effect on the volume of the sound. ...


0

Some of the decision is made by the compiler (or its authors) based on performance. E.g. your target hardware might allow to address memory on 1 byte granularity but only with a performance overhead of multiple cycles if the it is not aligned to 8 bytes. Not all the decisions about the memory layout are left to the compiler, if the compiler wants to produce ...


0

It’s based on what the underlying architecture supports - if you look at the instruction set for x86, everything's done in terms of bytes, words (2 bytes), longwords (4 bytes), and quadwords (8 bytes). There just aren’t any instructions for dealing with 6-byte entities (at least none that I know of). It’s just easier to use a fixed size, even if you don’t ...


3

It's not so much the compiler that decides, but the software developers creating the compiler. And they decide that based on what makes sense for the processor, and what customers (developers who use the compiler) want. For example, if you write a C compiler for a 64 bit ARM processor, your types can reasonably be 8, 16, 32 or 64 bit based on the hardware. ...


1

I have heard OpenGL described as client-server architecture. You don't have direct access to the actual resources on the GPU similar to how you dont have access to actual resources on a server, just handles. You can ask the server/GPU to do things but the server might ignore or defer the action related to the actual resource. Resources may become invalidated ...


1

Why are people coding “C-style C++”? Historic inertia. When C++ arrived, it was quite successful - a big hit. A lot of transitions of C code to C++ could be done with little re-work. Dual C/C++ development/maintenance was initially possible. C++ was looking to not be just another language, but a successor to C as ever increasing classes appeared.** ...


0

Always ask yourself the following question: If I test and there is an error, can I handle it in a meaningful way? If the answer is "No", then why would you test for it? E.g. lets take Hello World: #include <stdio.h> int main() { printf("Hello, World!"); return 0; } We all know, that printf() may fail. What are you going to do ...


Top 50 recent answers are included