« first day (1842 days earlier)      last day (1002 days later) » 

12:45 AM
Hello, I am not near a compiler and need a bit of help fast
will this code work? (one sec as I type)
main.h
```
#ifndef MAIN_H
#define MAIN_H
// User-Defined Headers

// 3rd Party Library Headers

// Standard Library Headers
#include <iostream>

#endif

class MyClass {
void Function();
};
```
Main.cpp
```
#include "main.h"
class MyClass {
int main() {
MyClass ClassObj;
ClassObj.Function();
}
```
oops
 
1:08 AM
`class Demo
{
public:
    boost::atomic<bool> flag;
};`
Demo demo;

Then `demo.flag.load()` is true or false?
Why?
 
 
2 hours later…
mr5
2:46 AM
I think the default value is false?
The why, is probably they mimic the primitive type default value?
 
 
2 hours later…
4:47 AM
It seems that there is no default value for boolean except when it's a global variable.
 
mr5
5:44 AM
Yeah probably the default value on the defined behavior case.
But idk. Maybe look straight into the docs
Nah, there is no default value: stackoverflow.com/a/36320050/2304737
How I wish there is a compiled docs for C++
 
6:09 AM
So, whether demo.flag.load() is true or false is not defined. Am I right?
 
mr5
yes
 
6:33 AM
@John it's guaranteed to be false since C++20 at least: en.cppreference.com/w/cpp/atomic/atomic/atomic
 
 
4 hours later…
10:59 AM
4 messages moved from Lounge<C++>
 
 
2 hours later…
12:29 PM
@JohnJameson next time you need a compiler you can just use gcc.godbolt.org
I assume pretty much any device that can use this chat, can use that website
 
PeterT, I see, thank you.
 
How fast is std::sort as compared to QuickSort
 
@Agent_A Depends on implementation and data
> O(N·log(N)), where N = std::distance(first, last) comparisons.
The better question is how much data do you have
and does it matter
it's important to remember that for small values of N... bubble sort or even bogo sort can be faster
 
mr5
1:19 PM
[self = shared_from_this()]
what is the advantage of that over this:
[self = this]
?
 
if you're using that pattern then you need whatever self is to last for the lifetime of the lambda
and it might otherwise not
I've used it to ensure that things live until all threads using it are exited
 
1:51 PM
Hey guys, really dumb question here; When do you actually want to use the static keyword? Every example that I have seen seems really dangerous if it is anything but const.
 
2:04 PM
if you need internal linkage on functions is a good place, but anonymous namespaces are better in C++
callbacks is another good place to use them so the method can be called without a this parameter
 
when would you need internal linkage?
 
when you don't need external ;p
basically if a method is never called outside of a TU it's always better to use internal linkage because the compiler can optimize the crap out of it
IMO you should default to internal linkage and only make visible things you absolutely need to
 
I guess I'm not sure I understand what you mean by always better to use internal linkage comment. Is that asking to make every variable static by default?
and function*
 
mr5
2:31 PM
how about static function inside a class? is that any better?
 
The static keyword is very confusing. I've been programming in C++ for like 7 years now and I still don't understand it. But I think static for functions and types have different meanings.
 
it does have multiple meanings. The storage duration/linkage one and the class member one.
 
the funny thing is, class data member static variables have external linkage
 
It's primarily useful for the linkage one
yeah static is weird because instead of making it easy they carried over the stupidity of C
 
2:38 PM
not only carried it over, but increased the stupidity as well
 
the best way to do internal linkage in C++ is IMO anonymous namespaces, particularly since compilers coughMSVCcough no longer have issues with them
 
mr5
ehe, I still want the OOP style
 
@mr5 this is extremely common for use as a callback?
 
mr5
I mean, when defining something like a "global function"
 
that's just bad practice unless it's actually related to something the class is doing
you should use a namespace otherwise
free functions are fine
 
mr5
2:47 PM
yeah, in my experience, it's always related to the class.
then I store it under utils folder
 
so related to the class means a lot of things. In many cases you're still better off not having them as static members
by related to the class I generally mean private things that need to be static for various reasons. Usually callbacks
but you can also do factory methods too
otherwise you end up with a static monster where everything is static and none of it makes sense
 
mr5
I only do static functions under class if it the class itself doesn't have any member variables.
 
then you shouldn't be using a class, you should be using a namespace
 
mr5
Generally, I just find it more readable to call it with the scope operator extended by its class name
 
don't create a type if you don't need to
you can do that with namespaces
but it's bad to create empty types that have no basis to exist
 
mr5
2:54 PM
why though
 
particularly for style reasons
 
mr5
it doesn't contain any member variables anyway
 
because the compiler still has to generate methods for them
it's still more crap for the linker to sort through
and it's abusing the type system for a stylistic thing
which is a major NOPE
 
3:12 PM
@Mgetz yeah, and I'm looking at a static monster right now and none of it makes sense. Hence why I asked this question because I'm wondering if the static monster needs to be there or if I should just remove the staticness from the code.
 
3:34 PM
ask yourself what the best refactor is:
* Make them members?
* Make them free functions?
* Nuke it from orbit?
 
I mean that is a hard question because literally everything in this class has the static keyword next to it, minus a few functions. But all the functions are declared static, and all of the protected variables are declared static, so I'm not sure how to answer the question lol
 
is your application multi-threaded?
if so... RUN
if not then start to analyze variable by variable if it needs to be global
it's going to suck
 
It definitely looks multithreaded. But it still runs slow af and I'm definitely going to have to go through variable by variable to see where a lot of the slowness comes from. I have seen a couple of vectors and strings passed by value here and there which can contribute to that as well. But I have a lot to dig through.
 
3:51 PM
don't assume it's code that's slowing you down just yet. profile first then change things
literally... don't touch anything until you've profiled
 
4:25 PM
yeah, that is my first step
then I will suffer
 
 
2 hours later…
6:35 PM
I can't figure out why this struct definition is out of scope, am I missing something obvious? Here is an exact copy/paste of the relevant section.

```struct SampleData {
private:
int data;
public:
SampleData(const int d) : data{d} {}
const int getNum() {return data;}
};


void testStackOnlyRingBufferAddInsideNewScope(Gib::RingBuffer<SampleData>& rb) {```
The errors are as follows:

DataStorageTests:42:63: error: 'SampleData' was not declared in this scope
void testStackOnlyRingBufferAddInsideNewScope(Gib::RingBuffer<SampleData>& rb) {
^~~~~~~~~~
DataStorageTests:42:73: error: template argument 1 is invalid
void testStackOnlyRingBufferAddInsideNewScope(Gib::RingBuffer<SampleData>& rb) {
 
nvm, can't look right
but yeah, did you include the header with that definition
and is the namespace visible there
 
Yes, I use the RingBuffer object in a different function without issue. This just popped up when I created a new function and tried to pass the templated object (RingBuffer) as a reference
It's all in a single file because I just wanted to test the scope for adding to an array on the stack
`void testStackOnlyRingBufferAddInsideNewScope() {
Gib::RingBuffer<SampleData> rb = Gib::RingBuffer<SampleData>();`

If I remove the parameter and create the object inside the function it compiles without issue. Is there something tricky about passing a templated object as a parameter? I haven't had trouble with this in the past.
 

« first day (1842 days earlier)      last day (1002 days later) »