Questions about C++, a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language.

learn more… | top users | synonyms

3
votes
0answers
149 views

Is it okay to write C code that must be compiled with -fno-strict-aliasing? [closed]

Some major C projects violate the strict aliasing rules in the C standard and must be compiled with -fno-strict-aliasing. These include Python, OCaml and the Linux kernel. Obviously this is not ...
1
vote
1answer
171 views

Data structure to use for time-optimized line-vs-grid check?

I am asking here because I feel that this question can be filed under the "algorithm and data structure concepts" category. Background: I have been recently assigned the task to design and develop a ...
4
votes
1answer
198 views

Optimal fixed-size sequential sorting algorithms

I have been working on sorting algorithms for a few weeks now, but one of my question still hasn't an answer: are there optimal sequential comparison sorts for fixed-size – and random-access – ...
5
votes
3answers
404 views

non-optional pointers vs. non-const references in C++

In Other C++ Features, Reference Arguments of the Google C++ Style Guide, I read that non-const references must not be used. All parameters passed by reference must be labeled const. It is clear ...
-6
votes
1answer
251 views

Using delete this to free memory in class

Whenever we are writing destructors in C++ (though this concept could apply in other languages) could we just not write delete this; and it would delete whatever data is inside of the class? Is ...
2
votes
1answer
94 views

How to generate learning material from your work [closed]

Catalyst: Recently my team has been tasked with bringing in house a large software project that has been worked on for over 20 years. Some of the old development team is still around, and originally ...
5
votes
8answers
306 views

Designing around shallow constness with inheritance

Background I'm writing an image handling class. For this question two requirements of the class are of interest: Must have "deep" const correctness. Must allow sub-image aliases, a.k.a. sections or ...
133
votes
11answers
20k views

Should I stop using the term C/C++?

I understand C and C++ are different languages but when I was learning C++ I was always told that C is a subset of C++ or C++ is C with classes. And that was quite true until the appearance of C++x0, ...
3
votes
3answers
343 views

C++ Extensible namespaces - how to force declarations back into global namespace

It is good programming style to include all necessary dependencies in a header that references them. Often this includes declarations that are placed in the STD & global namespaces (like cstdio). ...
1
vote
1answer
62 views

Threads Inside Full Duplex Device Library

This is the second project I'm working on which will use a design that I'm not 100% confident about. I'd like some feedback, maybe recommendations for a better design, or verification that this would ...
4
votes
2answers
170 views

Does returning pointer to composed objects violate encapsulation

When I want to create an object which aggregates other objects, I find myself wanting to give access to the internal objects instead of revealing the interface to the internal objects with passthrough ...
1
vote
1answer
98 views

Why some compilers do not synthesize the move operations at all per this paragraph in C++ Primer 5th?

In particular, if a class defines its own copy constructor, copy-assignment operator, or destructor, the move constructor and move-assignment operator are not synthesized. —— quote from "13.6.2. ...
3
votes
5answers
134 views

Can encapsulation be implemented by proper types rather than accessors?

Interesting question came up while designing interfaces at work, now resolved, but I want to ask about the theory behind it. Is it incorrect to say that properly typed data members of a class provide ...
3
votes
4answers
302 views

How to illustrate to students why they should use the standard library? [closed]

Too often I run into students who: Use arrays instead of vectors, thinking that it's "faster" Use pointers because it's "faster" Reinvent-the-wheel, often copying-pasting terrible C-ish code from ...
7
votes
3answers
560 views

C++ Header files design : just like defining an API?

I'm kind of new to large scale software development in C++, and I was wondering on the design side of things. I was reading this question, and I thought that, overall, once we get past constant ...
3
votes
0answers
566 views

Is it rational to convert protobuf into json to send it to a web server?

Protobuf is a good thing, it allows c++ devs to not bother with class serialization/deserialization, is fast and .proto format is very nice. It also allows automatic data validation. But the messages ...
3
votes
1answer
99 views

Eliminating thread affinity requirements when converting an STA COM object into an MTA COM object

Suppose I need to convert an STA COM object into an MTA object. Single threaded apartments guarantee not just that only one thread will call the object at a time, but that it's always the same thread ...
1
vote
0answers
131 views

Switching from Node.js class techniques to C++

I'm going to be rewriting a project from Node.js into C++11. The device the Node.js scripts are being run on are ARM based, and Node.js is slow to start up on the device. In the Node.js program, I ...
3
votes
2answers
234 views

When is it ok to assert for a pointer being non-null?

This came up as part of a code review for a code segment which resembled this: auto somePikachu = GetMeAPikachu(); NT_ASSERT(somePikachu != nullptr); // this only fires on debug build ...
7
votes
1answer
983 views

static globals and anonymous namespaces in C++

Why did C++ make any distinction between static globals (internal linkage) and symbols in an unnamed namespace (external linkage, but no way to refer to it from outside anyway), when introducing the ...
1
vote
2answers
152 views

Lots of independent data structures into one big one

I have 10 independent data structures that contain unsigned bytes and bit fields from different data sources. I am using C++, and was looking for a way to combine all these data structures into one ...
3
votes
2answers
277 views

Methods of “Code Softening” (Opposite of “Hardening”) for C & C++ [closed]

Some developers work on code hardening. (protecting against errors, you can build with a stack protector for example). However, if you're trying to redo a strange someone else reports, or find ...
3
votes
2answers
382 views

Should I also mock header files?

So, I am part of a very large project which has, as yet, no unit testing (shudder!) and I want to introduce it. I plan on using Google Test and Google mocks. The code is large and unwieldy and ...
6
votes
3answers
1k views

Is it good to define a variable inside a loop? [closed]

My instructor once told me that I should not define a variable inside a loop, but I honestly still do not understand why. What are the disadvantages of that? Could any body explain that to me?
12
votes
5answers
836 views

C++: Should class own or observe its dependencies?

Say I have a class Foobar that uses (depends on) class Widget. In good ol' days, Widget wolud be declared as a field in Foobar, or maybe as a smart pointer if polymorphic behavior was needed, and it ...
1
vote
1answer
48 views

Fill widget with data retrieved from internet

I want to retrieve data from internet and show them into a widget. In particular, I've a widget with a QComboBox containing some service from which I can retrieve a list of exchange markets. When I ...
4
votes
1answer
140 views

Refactoring numerical code for TDD and encapsulation

I am coming to terms with TDD, and the fact that I need to re-factor some code that I'm (re)writing. I am having a problem that I think is a classic conflict---TDD vs. encapsulation of private ...
1
vote
1answer
154 views

Using bool/flags to govern C++ program flow

I find myself consistently creating flags within my C++ program, that are later checked to determine if I need to do something, and it honestly feels kind of "hack-y" despite being a simple solution. ...
1
vote
2answers
84 views

Dynamic gesture recognition with fingertip points

I have built a fairly robust program in c++ which tracks several points on a hand. It accurately quantifies the size of the palm, the center of the palm, and the fingertip locations among other hand ...
1
vote
2answers
148 views

Will issues arise packaging libc and pthread with your C apps?

The issue I hit, is that I am packaging shared libraries with my code in order to load GNUTLS, except for libc, because I figured any system will have it. Most of them don't have the required 2.14 for ...
2
votes
2answers
705 views

Could Java import C++ classes from a library using JNA or JNI?

In past, I used JNI to access some winapi functions, however winapi is C and therefore just procedural. Now my plan is different and I need to know whether I'm going in the right direction. What I ...
2
votes
3answers
187 views

How to simplify structure of a monitoring software that uses the Observer pattern?

I am working on a project where I have to monitor the status of an elevator. So far, my design looks like this: We are using a third party library to read and monitor real-time values from the ...
-2
votes
1answer
109 views

Unnamed member access? [closed]

I'm trying to understand this piece of C++ code from a text book: template<typename T, int N> struct Buffer { using value_type = T; constexpr int size() { return N; } T[N]; // ... }; ...
0
votes
2answers
136 views

What exactly is interface compliance in C++?

I was reading this. It says that Some people believe that the purpose of inheritance is code reuse. In C++, this is wrong. Stated plainly, “inheritance is not for code reuse.” The purpose ...
1
vote
1answer
92 views

Best approach for aliases namespace from config

I'm working on a library that contains a large number of components that have namespaces that are nested. Also, when a new module inside the library get's added, we then have to add the namespace and ...
1
vote
0answers
425 views

Integrate C++ DLL with C# GUI asynchronously (design issue)

This is more a design than an implementation question. I am aware of how to integrate a C++ DLL within a C# main app that acts as GUI. Believe me that I've read all other questions on similar topics, ...
1
vote
1answer
435 views

What is the difference between “Wide character” set and “Unicode character set”? [closed]

Today I was reading my favourite C++ Programming book (C++ Primer Plus) and the section which was about variables and character sets in C++, however I got really confused about Unicode and Wide ...
3
votes
1answer
419 views

C++ Runtime and runtime-linking

I was installing boost and I came across an option named "runtime-link". After searching a bit, I came across yet another complex topic: "runtime system" that according to Wikipedia: The runtime ...
8
votes
1answer
528 views

C++ serialization design review

I am writing a C++ application. Most applications read and write data citation needed and this one is no exception. I created a high level design for the data model and serialization logic. This ...
1
vote
1answer
95 views

When's a resource a resource?

So I have a rendering engine, and I have a resource manager that adds classes that derive from type 'Resource'. It's a very flexible and generic resource manager, of which only one can exist (it is a ...
0
votes
1answer
109 views

Deciding on a software license for a C++ API [closed]

I have designed and developed a C++ API. Its dependencies are: BLAS - custom license - http://www.netlib.org/blas/#_licensing LAPACK - modified BSD - http://www.netlib.org/lapack/LICENSE.txt GLPK - ...
2
votes
1answer
242 views

Refactoring a god Manager class

I am running in the exact problem Robert Martin mentioned when having a class named Manager, mine has too much (redudant) code. I am writing a system doing computations on many buffers containing ...
4
votes
5answers
2k views

Checking array size in C/C++ to avoid segmentation faults

So it's well known that C does not have any array bounds checking when accessing memory. Nowadays, if you call myArray[7] when you initialised it as int myArray[3], your program will get a segfault ...
1
vote
1answer
559 views

What is an efficient data structure for syntax highlighting in text editors?

I'm creating a very small text editor in C++ with the ncurses library. So far, it works great. I have implemented the Gap Buffer data structure to make the editing more efficient than a line-based ...
4
votes
1answer
303 views

Genesis of C++ temporary object lifetime extension

I'm revising a proposal to expand the C++ feature where "temporary" objects cease to be temporary when attached to a name by binding a reference. Here's a sample of the classic behavior (not the ...
4
votes
2answers
458 views

Can higher order functions ever be pure?

I was thinking about pure functions especially in the context of C++, which of course is not a purely functional language, and was wondering if higher order functions in C++ can ever be considered ...
4
votes
1answer
123 views

Makefile for library project to be able to compile the unit tests and the demo program using make

I am new to makefiles and I am developing a (non-executable) library in C++. Additionally to the library I have (executable) unit tests and an (executable) demo program. I would now like to be able ...
2
votes
1answer
168 views

Multithreading with triple buffer, do I have to do the waiting for the condition variable?

I have a triple buffer implementation that is often used in threads in such a way that when new data is expected, there's always a WaitData(n) function called on the buffer (A condition variable's ...
3
votes
3answers
363 views

Possible alternatives to copy constructors

In my C++ project I am relying on some libraries that do memory management for me. I make wrapper classes, for ease of use and memory safety, for example the class below. Note that this is a much ...
7
votes
1answer
487 views

Key / Value store development porting to modern C++

I am developing a database server similar to Cassandra. Development were started in C, but things became very complicated without classes. Currently I ported everything in C++11, but I am still ...