Data dodania Pytanie
2017-11-29 01:11 g++ warning: conversion to uint16_t from int may alter its value »
At the advice of a high rep SO user, I've recently started compiling with the -Wconversion flag on my codebase. This has generated quite a few warnin...
(2) odpowiedzi
2017-11-28 19:11 Why does the ternary operator with commas evaluate only one expression in the true case? »
I'm currently learning C++ with the book C++ Primer and one of the exercises in the book is: Explain what the following expression does: someValue...
(5) odpowiedzi
2017-11-28 13:11 Why isn't there an endianness modifier in C++ like there is for signedness? »
(I guess this question could apply to many typed languages, but I chose to use C++ as an example.) Why is there no way to just write: struct foo { ...
(9) odpowiedzi
2017-11-28 10:11 No use of base object allowed in private inheritance »
I am using private inheritance, and I am surprised to see that in the derived class use of any base object is not allowed. class A; class B : private...
(2) odpowiedzi
2017-11-27 23:11 C++: Why does numeric_limits work on types it does not know? »
I have created my own type, without any comparator, and without a specialization of std::numeric_limits. Despite that, for some reason, std::numeric_l...
(1) odpowiedzi
2017-11-27 20:11 What does it mean for `offsetof` to be "conditionally-supported" for non standard-layout classes in C++17? »
The C++17 Standard says: [support.types.layout] Use of the offsetof macro with a type other than a standard-layout class is conditionall...
(1) odpowiedzi
2017-11-27 09:11 Accessing public static members of a base class specified as private »
I'm learning C++. The documentation docs.microsoft.com/en-us/cpp/cpp/member-access-control-cpp says: When you specify a base class as private, it ...
(2) odpowiedzi
2017-11-26 21:11 Weird Execution Times »
The problem is about getting some discontinuities in the execution time sequence for various input sizes. Specifically, I have been trying this code: ...
(1) odpowiedzi
2017-11-26 17:11 What does "compares < 0" mean? »
Introduction English is a foreign language for me and I just began learning C++, so please bear with me. While I was reading Consistent comparison, I...
(7) odpowiedzi
2017-11-26 14:11 static_assert before a constructor's initialiser list »
There is a non-templated class which has a templated constructor. Is it possible to check a static assertion before initialising member variables in s...
(2) odpowiedzi
2017-11-25 20:11 Name conflict between namespace and class template: different compiler behavior »
Different compilers show different behavior compiling the following code: namespace N { namespace Foo { template <typename> ...
(1) odpowiedzi
2017-11-25 15:11 Is data allocated on the heap slower to access than data allocated on the stack? »
I've heard conflicting opinions on that matter. Some say that accessing data allocated on the heap (ie std::vector or dynamic arrays allocated throug...
(2) odpowiedzi
2017-11-25 13:11 How and why did the ISO C++ Standards Committee (WG21) decide to accept the proposal for a spaceship operator as it is? »
In a recently published paper [1], Herb Sutter et al. describe an extension of the programming language C++ by a three way comparison operator. The au...
(0) odpowiedzi
2017-11-25 00:11 Is putting integers into a vector, and then sorting faster, or putting integers into a set »
Is pushing integers into a vector, and then sorting the entire vector faster or slower than inserting the integers into a set, which sorts as you ente...
(2) odpowiedzi
2017-11-25 00:11 What is the purpose of std::byte? »
Now that c++17 has std::byte, I was looking for a way to convert code that reads files to char into code that reads files into byte. A file contains b...
(1) odpowiedzi
2017-11-24 13:11 Placement new and assignment of class with const member »
Why is that undefined behaviour? struct s { const int id; // <-- const member s(int id): id(id) {} s& operator =(con...
(1) odpowiedzi
2017-11-24 07:11 Why do user-defined string literals and integer literals have different behavior? »
I'm learning about user-defined literals, and confused with the following test code: std::chrono::seconds operator"" _s(unsigned long long s) { r...
(1) odpowiedzi
2017-11-24 05:11 What is the <=> operator in C++? »
While I was trying to learn about C++ operators, I stumbled upon a strange comparison operator on cppreference.com,* in a table that looked like this:...
(3) odpowiedzi
2017-11-23 15:11 Declaration of variable in C++ »
Recently I saw a quite old code in C++, where int var(12) was used instead of int var=12. Why does it work? And should I avoid writing this style of d...
(2) odpowiedzi
2017-11-23 15:11 Order of static destructors »
If a class Foo has a static member variable Bar, I would expect Bar's destructor to run only after the last instance of Foo's destructor runs. This do...
(5) odpowiedzi
2017-11-23 14:11 Typo: bool to int conversion induced error in std::ifstream under Linux »
I had a typo (|| instead of |) and noticed such a code fails with GCC and compiles with Visual. I know that the second parameter of std::ifstream is ...
(1) odpowiedzi
2017-11-23 11:11 Print macro values without knowing the amount of macros »
I have code that includes a generated file (I don't know in advance its content), there is just a convention upon which me and my users agreed on how ...
(2) odpowiedzi
2017-11-23 10:11 #include guard before or after comment block? »
I have somewhere read (sorry can't find the link anymore) that on the first line of a header should always be the #include guard, because compilers ca...
(1) odpowiedzi
2017-11-22 17:11 Finding out whether static initialization is over »
The abridged problem (Y) Suppose you need to know, from within a function, whether this function has been called as part of the initialization of a s...
(1) odpowiedzi
2017-11-22 17:11 Can you bitwise shift a bool in C++? »
I'm using someone else's code that was written with an older compiler that mapped a special BOOL type to an unsigned int, but in my compiler it's mapp...
(1) odpowiedzi
2017-11-22 15:11 Is it undefined behavior to read and compare padding bytes of a POD type? »
Today I've encountered some code that roughly looks like the following snippet. Both valgrind and UndefinedBehaviorSanitizer detected reads of uniniti...
(3) odpowiedzi
2017-11-21 14:11 How to include data object files (images, etc.) in program and access the symbols? »
I've turned a couple of resource files into .obj files using objcopy and i link them with my programs source code. I can very well access the symbols ...
(4) odpowiedzi
2017-11-21 10:11 How to include makefile dynamically »
Now I have two makefiles, A.mk and B.mk. A.mk will include B.mk But B.mk is dynamically generated by some command which is executed in A.mk Here is ...
(1) odpowiedzi
2017-11-21 01:11 Parsing Mixed Binary Data in C++ »
I have a blob of data I am parsing. It has mixed data types, some doubles followed by some floats. This is how I have gone about parsing out the doubl...
(1) odpowiedzi
2017-11-20 17:11 Stepping into a function, but not into the evaluation of the arguments with VS2017 »
If often encounter following situation: int HelperFunction(int somevalue) { ... } void FunctionToDebug(int somearg) { ... } ... ...
(1) odpowiedzi
2017-11-20 14:11 Using global namespace qualifiers with pointer to data members »
I'm experiencing a compile error when attempting to use a pointer to data member when including the global namespace qualifier on the struct. I've red...
(1) odpowiedzi
2017-11-20 11:11 Repeated access to properties and speed in C# »
I usually work with C++ but I have more and more to write and maintain C# code. Now I see very often in C# code like this: Application.Current.Prope...
(0) odpowiedzi
2017-11-20 01:11 Is there any hope to call a common base class method on a std::variant efficiently? »
The way std::variant dispatches to different visitor methods when std::visit is called is pretty reasonable when the variant alternatives are complete...
(1) odpowiedzi
2017-11-20 00:11 In C++14, in which scope are unscoped enumerators of redeclared enumerations declared? »
The C++14 (precisely, N4296) says with respect to enumerations, in 7.2:11: Each enum-name and each unscoped enumerator is declared in the scope ...
(0) odpowiedzi
2017-11-19 20:11 How to correctly include C++ static library to iOS project »
I have a project which contains C++ static library (mylib.a), header for it (mylib.h) and objc class which use functions of this library (.h/.m). I'm ...
(2) odpowiedzi