recentpopularlog in

MaxBarraclough : c++   146

« earlier  
C++/MSVC - Disable single warning error
#pragma warning disable 1234
#pragma warning restore 1234

This avoids the nasty business of messing around with #warning(pop)
C++  VisualC  StackOverflow 
19 days ago by MaxBarraclough
Windows C++: how to ensure MultiThreadedDebugDLL is used as runtime
This is vital if objects allocated on one side of the DLL boundary are destroyed on the other side. If it is not done, you may end up with two different heaps, and the obvious associated trouble.
C++  WindowsDev  buildSystems  linking  StackOverflow 
23 days ago by MaxBarraclough
John Carmack on Inlined Code | Hacker News
HN discuss Carmack’s thoughts on the advantages of large functions

Carmack also discusses the Gripen's style:

> disallowed both subroutine calls and backward branches, except for the one at the bottom of the main loop

This branch-forward-only style is also discussed at , and
HackerNews  programming  programmingStyles  discussion  C  C++ 
24 days ago by MaxBarraclough
Implicit conversions -
On floating-point -> integer conversions:

> If the value cannot fit into the destination type, the behavior is undefined (even when the destination type is unsigned, modulo arithmetic does not apply)
9 weeks ago by MaxBarraclough
Google C++ Style Guide says all reference-type params must be const
> References can be confusing, as they have value syntax but pointer semantics.

> Within function parameter lists all references must be const
C++  codingStandards  Google 
december 2019 by MaxBarraclough
Stringification - The C Preprocessor
You probably want to do:

#define STRINGIFY(s) #s
C  Cpreprocessor  C++ 
december 2019 by MaxBarraclough
GCC Instrumentation Options
Interesting excerpt:

> integer promotion rules must be taken into account. That is, the following is not an overflow:
> signed char a = SCHAR_MAX;
> a++;

For more on -ftrapv etc, see

"-fsanitize=null" etc are described here
C  C++  GCC  undefinedBehaviour 
december 2019 by MaxBarraclough
Const Correctness, C++ FAQ on a rare case with ‘mutable’
> Write code that is guaranteed to work, not code that doesn’t seem to break.
december 2019 by MaxBarraclough
The const_cast operator (C++ only)
Pointer casting trickery to modify a const var, is UB
december 2019 by MaxBarraclough
SO discuss Abominable Function Types in C++
> void() & is not a reference to void(). The way to spell that would be void(&)()
> What void() & actually refers to is the type of a reference-qualified member function after you strip off the class
C++  StackOverflow  discussion 
november 2019 by MaxBarraclough
C++ Order of evaluation
In an assignment, right-hand-side expression is (now) evaluated first. (Previously there was no such sequence-point in the standard.)

"In every simple assignment expression E1=E2 and every compound assignment expression E1@=E2, every value computation and side-effect of E2 is sequenced before every value computation and side effect of E1"
october 2019 by MaxBarraclough
Please Calculate This Circle’s Circumference | Random ASCII
An excellent dive into floats/doubles and handling constants in C++

"integral constants in header files don’t allocate storage, whereas non-integral constants do. This distinction is poorly understood, and occasionally important."
C++  blogEntries  C 
october 2019 by MaxBarraclough
C++ zero initialization - Why is `b` in this program uninitialized, but `a` is initialized? - Stack Overflow
Declaring constructor with `Bar();` is not equivalent to using `Bar() = default;`, even if you later define with `Bar::Bar() = default;`
C++  StackOverflow  discussion 
february 2019 by MaxBarraclough
scope(exit) in C++11 – The Witness
a blogger reinvents BOOST_SCOPE_EXIT, and discovers the horrors of std::function
C++  Boost  blogEntries 
december 2018 by MaxBarraclough
'throwing nothing' C++
`throw;` means rethrow. If there's no current exception to rethrow, it's tantamount to calling std::terminate(), and does not perform the stack-unwinding and cleanup that you'd expect.

C++  exceptionHandling  StackOverflow 
december 2018 by MaxBarraclough
What are Aggregates and PODs and how/why are they special? - Stack Overflow
not quite the same thing as 'standard-layout', which might be what you really care about, and is weaker (i.e. a strict superset of POD)
StackOverflow  C++ 
december 2018 by MaxBarraclough
a word of warning re. Microsoft's LARGE_INTEGER
> MS uses the LARGE_INTEGER union for passing such long long values for both historical reasons and for forcing alignment of the long long. Some of the Windows API will crash if Quadpart is not aligned correctly. So simply casting an __int64* to LARGE_INTEGER* in calls to the Windows API is not good practice.

Also and and
C++  WindowsDev 
november 2018 by MaxBarraclough
is_trivial - C++ Reference
> A trivial class is a class (defined with class, struct or union) that is both trivially default constructible and trivially copyable

cf. the has_trivial_constructor trait
november 2018 by MaxBarraclough
Explicitly Defaulted and Deleted Functions
it's possible to prevent 'new' being used, for instance
november 2018 by MaxBarraclough
value initialization(since C++03) -
Madness follows the uniform init. syntax.

To be truly sure all members have been initialized, it is still not enough! If there is an empty user-defined default constructor, you just get default init. as usual, so it remains possible that a member could be unassigned. You could static_assert on has_trivial_constructor I suppose. See also the restrictions and consequences of the new syntax at
november 2018 by MaxBarraclough
how to have g++ treat 'reordering' as a full error
'Reordering' as in where initialization lists have an order which fails to match the order of the members' declarations (recall that it's the latter that dictates initialization and destruction order): `-Werror=reorder`
C++  g++ 
november 2018 by MaxBarraclough
GotW #88: A Candidate For the “Most Important const” | Sutter’s Mill
`const string& s = f();` is legal/precisely defined/well-behaved

Special behaviour regarding which destructor gets invoked.

C++  blogEntries 
november 2018 by MaxBarraclough
Is cin/cout slower than scanf/printf? - Quora
consider using

july 2018 by MaxBarraclough
[large PDF] Thinking in C++ 2nd edition Volume 2
page 347 explains that, contrary to most half-baked explanations, virtual inheritance does not let the compiler somehow intuit which method you mean. Explicit disambiguation is required even after you've used virtual inheritance to prevent multiple instantiations of the grandparent class.
C++  objectOrientedProgramming  ebooks 
july 2018 by MaxBarraclough
Virtual Inheritance in C++, and solving the diamond problem -
"if either transmitter or receiver attempted to invoke the storable constructor in their initialization lists, that call will be completely skipped when constructing a radio object! Be careful, as this could cause a subtle bug!"
C++  objectOrientedProgramming 
july 2018 by MaxBarraclough
What are the rules about using an underscore in a C++ identifier? - Stack Overflow
SO discuss the precise rules of when the language permits this terrible idea. Be sure to follow the Personal Rules of :

* Never start a symbol with an underscore
* Never name a symbol with two consecutive underscores inside

and abandon hope all ye heedless

Don't forget the peculiar further restrictions imposed by POSIX, described in linked answer.

Also, re. C:
StackOverflow  C  C++  discussion 
june 2018 by MaxBarraclough
Unions and type-punning - Stack Overflow
> type-punning through unions is perfectly fine in C (but not in C++)

Another answer says it’s ‘unclear’ whether it’s UB in C++.

Assuming this is correct, the otherwise excellent is wrong about this

See also
C  C++  StackOverflow  discussion 
june 2018 by MaxBarraclough
c++ - What does "int* p=+s;" do? - Stack Overflow
Apparently there's a relevant difference between C and C++ here, re. the unary + operator on certain types
C  C++  StackOverflow 
may 2018 by MaxBarraclough
« earlier      
per page:    204080120160

Copy this bookmark:

to read