56,765 questions
-1
votes
2
answers
112
views
Reinterpret_cast array of bits as byte [closed]
I want to cast an array of bits into a byte, it works by using a loop and bitshift, but I think it would be cost inefective if run repeatedly (I might be wrong). So I wanted to use a pointer with ...
11
votes
1
answer
817
views
Can formal parameters inside the function not be dropped even if the function returns until the caller statement ends?
I have tried some compilers and some C++ standard versions. This code may have a deadlock (the comments point out that this is UB) and can be reproduced at least under gcc8 and C++11. I use "...
1
vote
2
answers
96
views
Sequence of Events in : mutex.unlock() vs returning from a function
short brief - I want to understand the sequence of event when returning from a function and unlocking a mutex in the same function.
helper macro: to print to screen
#define TRACE() {std::cout <&...
4
votes
1
answer
127
views
How to create a std::shared_ptr with the same control block as an expired std::weak_ptr
TL;DR How can a std::shared_ptr be created from an expired std::weak_ptr so that it uses the same control block as the std::weak_ptr?
I ran the following test case, and noticed two oddities:
#include ...
5
votes
1
answer
93
views
minimum required atomic instructions to support C++11 concurrency libraries
I'm implementing a multi core system consisting of several custom/specialty CPUs. Those CPUs need to be able to support the C++11 concurrency libraries (thread/mutex etc.).
I'm not sure what kind of ...
3
votes
3
answers
195
views
Receiving a lambda through auto&&
If I assign a lambda in C++ with this:
auto&& mylambda = [&](int someparam)
{
some_function();
return 42;
};
Is this wrong? I know that this triggers auto type deduction, but is ...
2
votes
1
answer
132
views
Using std::move with Constructor(Type t) or Constructor(Type&& t). What's the difference?
I'm studying std::move semantics and I would like this to be clarified to me:
Say I have:
// Message.h
class Message
{
private:
std::array<uint8_t, BUFFER_SIZE> buffer;
std::queue<...
2
votes
1
answer
82
views
C++ OpenSSL 3.0.8 private key decryption with EVP_PKEY_decrypt failed
I haven't find solution by myself and need help.
I'm writting simple client-server encrypted chat programm using OpenSSL 3 library.
Client's and server's socket parts both inherited via '...
0
votes
2
answers
99
views
How to infer whether a global sequence is valid or not with std::memory_order_seq_cst?
#include <atomic>
#include <thread>
#include <cassert>
#include <chrono>
std::atomic<int> x {}, y {};
void write_x_and_y() {
x.store(1, std::memory_order_seq_cst); ...
0
votes
1
answer
64
views
build gRPC++ with only C++11 and no Absl
I am trying to use protobufs and gRPC on a legacy system that runs Ubuntu 14.04 and C++11, and that can't be updated.
I have tried building gRPC v1.46.7 (the newest version that does not require C++14 ...
3
votes
2
answers
250
views
How to avoid use of long in C++?
I work on a very large C++11 codebase, and we want to prevent future developers from declaring variables as long, since using long causes some issues when compiling on Windows compared to Linux.
Our ...
-2
votes
1
answer
122
views
Assign thread object after the join function in C++
As per my understanding it is fine to assign the thread object and call join function in C++ 11.
eg as below :
#include <iostream>
#include <thread>
using namespace std;
void func()
{
...
0
votes
2
answers
64
views
Warning elimination - potentially unsafe code
The code below throws a warning about possible loss of data:
std::string Converter::tolower(const std::string &value)
{
std::string data = value;
std::transform( data.begin(), data.end(), ...
2
votes
2
answers
121
views
Value categories in C++: What does "can be moved from" mean?
In C++, the value category of an expression is determined by two independent properties:
Whether the expression has an identity
Whether the expression can be moved from
(References: cppreference and ...
1
vote
1
answer
137
views
How do I not-repeat-myself with this redundant method name prefix?
I'm writing a library which has a queue object (not std::queue and not usable as a C++ container). On this queue, we can enqueue commands, with arguments. Let's say the commands are foo, bar and baz, ...