« first day (1841 days earlier)      last day (1003 days later) » 

mr5
7:54 AM
err, the initialization syntax is weird.
 
if it works, it works :P
isprime = trial % *(primes+i)>0;

can mean different things, depending on what the type of "primes" is. But it's probably just

auto remainder = tiral % primes[i];
isprime = remainder > 0;
 
mr5
isn't that mod and multiply operator?
iirc, that is not allowed?
 
no, that's unary *
exactly because binary * isn't applicable here
 
mr5
oh
why do some people like to obfuscate their code
isprime = trial % *([primes]+i) > 0
this will work too right?
 
I don't think so
 
mr5
8:01 AM
there
 
I don't see anything being operated on with []
 
mr5
I have seen some weird syntax on some comments before. Can't remember exactly how it looks like.
[v]+0
v + 0
[v]0
something like that
 
I think you mean 0[v]
 
mr5
so it would be i[primes]?
 
 
1 hour later…
9:18 AM
How to understand this code snippet?

class CustomTimer
{
public:
template <class callable, class... arguments>
CustomTimer(int after, bool async, callable&& f, arguments&&... args)
{
std::function<typename std::result_of<callable(arguments...)>::type()> task(std::bind(std::forward<callable>(f), std::forward<arguments>(args)...));
}
}
 
9:29 AM
it's binding the arguments of some callable you pass in and storing that in a std::function
makes int f( T a, M b, N c) -> int f() , by giving values for a,b,c
 
`std::result_of<callable(arguments...)>` obtains the result type of a call to Fn with arguments of the types listed in ArgTypes.
So, `typename std::result_of<callable(arguments...)>::type()` is just a return type of the `callable`, e.g int, bool and etc.
Then, std::function<typename std::result_of<callable(arguments...)>::type()> should deduced to std::function<int> or std::function<bool> and etc...
But in general, we declare a std::function like this: std::function<int(void)> other than std::function<int>
 
that what the "()" after type is
it's
using returnT = typename std::result_of<callable(arguments...)>::type;
std::function <returnT()> task(...)
 
I see, thank you so much!
 
9:45 AM
Out of curiosity which version of C is the Linux kernel written in?
 
9:56 AM
I think mostly C89, there's gotta be plenty of modules that use C99 though, never looked it up though
https://stackoverflow.com/questions/20600497/which-c-version-is-used-in-the-linux-kernel

> The implication is that the kernel must work with user code written in C90.
> the GNU dialect of ISO C90 (including some C99 features).
 
10:53 AM
Hello. I wanted to know does a faster GPU helps with simulations I am running in VS code (or any other IDE). Please @ me when you answer. The answers usually get lost. Thanks.
 
@Shobhit only if your "simulations" use GPU APIs
because "simulations" could mean anything
 
11:23 AM
```void fun(unique_ptr<char> &obj)
{
obj = make_unique<char>();
}


int main()
{
unique_ptr<char> ptr;
}```
Is this UB?, the fun is taking a reference to null
 
I don't see a call to fun in that example
but I also don't see any UB in there
if you do fun(ptr); it's fine, but fun(*static_cast<unique_ptr<char>*>(nullptr)) is just wrong
 
sorry missed it
is it a good practice?
 
having a default initialized unique_ptr ? seems fine to me
 
i have two unique_ptr as a member variable of a class
the member function create the unique_ptr based on what is passed
class A {
unique_ptr<char> member1;
unique_ptr<char> member2;

void fun(unique_ptr<char>& arg)
{
arg = make_unique<char>();
}

void fun2()
{
fun(member1);
fun(member2);
}
};
something like this
 
11:44 AM
@PeterT They do not. Just extensive for and while loops. (10 Billion)
 
@Shobhit unless you compile it with something special, normal C++ won't magically use the GPU for normal code
I think there's like some OpenMP implementations and some parallel STL implementations that can use the GPU, but you need to write code with the GPU in mind, to make use of it
 
@PeterT ok. Thank you. So it depends on RAM? or processor? (sorry I do not know these things)
 
otherwise you just end up spending more time copying memory back and forth than you would have taken just doing it on the CPU
depends on what you do, your program could be memory bandwidth bound or CPU compute bound
Your program will not get infinitely faster if you keep upgrading ram, neither will it infinitely get faster if your CPU gets upgraded more and more if you're interacting with memory.

So unless you examine what the bottleneck is at the moment, you cannot just say "it's always the RAM" or "it's always the CPU"
 
If you want to know your bottleneck you need to profile, tune, then profile more
 
too much work. Thank you for your input guys. I'll just stick with increasing priority of my program by task manager (I have seen this makes my simulation run much faster).
 
12:32 PM
Has anyone ever seen that all the member functions of a specific class are static methods?
 
Yes, but only by people that don't understand namespaces
it's generally a bad idea
 
it's generally a bad idea.
>Why, could you please explain that in more detail for me? I just saw such an implementation. I think it's odd, but I can't figure out what's wrong with it.
 
so if it's all static members (assuming the class has no data members) then a namespace is a better choice
if the class does have data members then the methods should be free functions in the namespace
or if they access private values they should be non-statics
 
The data members are all static variables, too.
 
yeah that's worse
that's basically C and misusing a class
they should just be using a namespace
I can't comment on if they should be using instance members, but globals are bad. Static data members are globals
 
12:40 PM
I see. Thank you for your detailed explanation. My understanding of this matter is at a different level with your generous help.
 
mr5
Do you know how to get rid of "multiple definitions" error when defining a non-static global function in header file?
 
mark it in inline or don't define the definition in a header?
 
mr5
Aside from adding the inline keyword and the template hack
 
static works
 
you can't escape ODR
static just makes your binary bloat
by creating a new copy in every single TU
 
12:43 PM
Yes
 
mr5
oh, is that how static function works in C++?
 
you can just do the "right" thing and not put it in the header if you don't want it to be inline
 
mr5
What is ODR?
Eh, I don't want to make a .cpp file
 
static creates internal linkage, meaning that the method isn't visible outside of that TU
 
not to mention that "inline" doesn't mean "always inline", just "if you think it's a good idea, the inline it"
 
12:44 PM
One defintion rule
anything without internal linkage must be defined in the linked program once
 
you can do it the dirty way that single header libs do it sometimes, but I'm not going to encourage that
 
mr5
Also, one reason I am defining the body in header file is I have something like this:
struct X { }; // X.hpp
struct Y<T> { }; // Y.hpp Y<X> use like

// required by nlohmann (JSON serializer/deserializer library)
from_json(X&);
to_json(const X&);
And I am using this Y<X> on multiple models.
So if I didn't put the definition on header file, I would have to specialize the template for each model I think?
@PeterT what is that way?
 
I don't understand why inline is such a problem if you don't want a seperate cpp file
 
mr5
oh I didn't read your previous message
I have read the explanation on SO. It seems inline keyword has lost its meaning already. So why not just ignore the "multiple definition" error.
 
it still has a meaning, the meaning just isn't "always inline".
 
mr5
12:54 PM
Like, if the function is defined on header file, do the inline magic thingy
 
Technically you could try to do token for token comparison between all definitions to make sure they don't violate ODR, but why add that complexity
 
mr5
It will make the devs life more easier if they just enabled it by default.
 
name-collisions and people doing weird macro checking in functions would just spread ODR violations all over the place.
especially when you try to link already compiled static libs or dynamic libs, how are you going to decide which one is the real name?
 
mr5
prioritization?
so dynamic libs -> static libs -> executable
then if multiple definition occurs per category, prioritize based from chronological order
 
It just seems way to error prone with the current linking model.

If you're making a new language, then I agree that the definition/declaration separation doesn't make much sense. But I don't like trying to retrofit it to C++
 
1:00 PM
There is such a language it's called C#
 
mr5
yeah, at this point, that is too much to ask.
 
I would even be fine with it if they added like a "#pragma cpp2023" to change the rules per compilation unit. I just wouldn't want to break old code.
 
1:25 PM
yeah until someone adds that to a header
 

« first day (1841 days earlier)      last day (1003 days later) »