« first day (1769 days earlier)      last day (1090 days later) » 

7:42 AM
One quick c++ syntax query. There is a function signature like so:

https://github.com/nodejs/node/blob/b34a9d7dd88b6d717448e0ff433158c845f2f309/src/node_file-inl.h#L222

note the 3rd argument is `bool`.

Does the compiler allow calls like so:

https://github.com/nodejs/node/blob/b34a9d7dd88b6d717448e0ff433158c845f2f309/src/node_file.cc#L1718 (note: 3rd argument omitted).

So will the 3rd argument be taken as `false`?
 
@deostroll not by default, no. It's probably somehow getting this signature github.com/nodejs/node/blob/…
 
8:11 AM
Thanks. It was VS code that navigated to that specific inline implementation... :(
 
8:26 AM
well vscode wasn't wrong, that's where the implementation was. It's just that you can't repeat the default parameter in both the declaration and definition if they're seperated
 
 
4 hours later…
12:15 PM
@deostroll Not using clangd then :)
@PeterT Ah.
 
More syntax queries!!!

https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/src/node_file-inl.h#L251

^ This is a call to a method call Dispatch() - note the last argument. Also note we are passing variable arguments.

This is the definition: 👇

https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/src/req_wrap-inl.h#L139

So will the "args" variable coming the above function definition capture the last argument ("after" which is passed at invocation time)?
I don't think there is another matching signature for Dispatch() in the source of node.
@sehe is there a possibility that this might clash with other c/cpp vscode extensions?
 
@deostroll Yeah, but you won't mind doing without "competing" intellisense. And it doesn't clash (on the contrary) with things like cmake support
@deostroll "So will the "args" variable coming the above function definition capture the last argument" - yes. en.cppreference.com/w/cpp/language/parameter_pack
 
@sehe Cool thanks. đź‘Ť
 
12:31 PM
12 messages moved from Lounge<C++>
 
 
1 hour later…
1:46 PM
If the type of `val` is uint16_t, is there any difference between (int16_t) uVal
and *(int16_t*)&uVal ?
 
2:13 PM
It seems that they are equivalent. But I can't figure why.
Here is related code snippet:

#include<iostream>

void foo(uint16_t uVal)
{
int16_t auxVal1 = (int16_t) uVal;
uint16_t auxVal2 = *(int16_t*)&uVal;

std::cout << auxVal1<< std::endl;
std::cout << auxVal2<< std::endl;

std::cout << (uint16_t)auxVal1 << std::endl;
std::cout << *(uint16_t*)&auxVal2 << std::endl;
}

int main()
{
foo(0xFFFF);
std::cout << std::endl;

foo(1);

}

Here is the output:

-1
-1
65535
65535

1
1
1
1
 
@John they're the same if the value your're casting is the same size as the target value
if you're casting char, int or even double then it'll be a lot different
but I think signed overflow is still technically undefined behavior
 
2:43 PM
@PeterT [stackoverflow.com/questions/4975340/…( "As has been noted in the other answers, the standard actually guarantees that "the resulting value is the least unsigned integer congruent to the source integer (modulo 2n where n is the number of bits used to represent the unsigned type)". So even if your platform did not store signed ints as two's complement, the behavior would be the same.")
 
yeah that's about the signed->unsigned conversion though, right?
 
 
1 hour later…
4:12 PM
I'm writing a simulation, which involves the generation of a huge number of random numbers, according to some normal distribution. I want to apply multiple algorithms to this same set of numbers, so as to more-or-less compare the results. The issue is, the dataset is much too large to store in memory.
Each algorithm can be fed the numbers one-by-one, so my idea was to just properly seed the RNG such that it produces the same sequence of numbers each time. My question is, if I have: default_random_engine generator(seed); normal_distribution<double> distribution(mean, rms);, if the seed is the same each time, am I guaranteed to get the same sequence of numbers?
It appears to work, and certainly works this way with other RNGs, but I know nothing about using the C++ RNGs.
 
with the same compiler/stdlib implementation they stay the same, but they're not portable. So if you build/execute it on another machine, you might get different numbers
 
@PeterT Got it, thanks!
 
 
3 hours later…
7:36 PM
Q. Which Resolve() is being called here?
 
8:28 PM
Hello, just a simple question, how to declare a variable from a class with a constructor requiring arguments?
-3
Q: How to just declare a variable using a class with a constructor requiring parameters?

user2284570I have the following non thread safe inside an Openmp for loop bneijt::MetalinkFile record(filename, &mirrorList); because the constructor at the same time updates mirrorList which is a vector used after the loop and thus has to be shared among all threads. Where the MetalinkFile class is class ...

I know about
1
A: How do I make define and declare a variable using the default constructor in C++?

YttrillMyClass instance; is also a definition, using the default constructor. If you want to merely declare it you need extern MyClass instance; which is not a definition. Both, however, have external linkage.

but as the constructor of myclass requires arguments, it doesn’t work.
 
 
2 hours later…
10:47 PM
@user2284570 damn, I don't understand why people are downvoting that question
You can do something like this
std::unique_ptr<bneijt::MetalinkFile> record;
#pragma omp critical
{
record.reset(new bneijt::MetalinkFile (filename, &mirrorList));
}
If that level of indirection is not accaptable, you can also do
std::optional<bneijt::MetalinkFile> record;
#pragma omp critical
{
record.emplace(filename, &mirrorList);
}
 
11:05 PM
@PeterT In that second case, should I rewrite the code using record or can I use record as if it was instanciaed directly?
 

« first day (1769 days earlier)      last day (1090 days later) »