« first day (1484 days earlier)      last day (1372 days later) » 

9:18 AM
#include <stdio.h>

int main(void) {
    int one = 1, two = 2, three = 3;

    for (int *const end = &three, *iterator = &one; end != iterator; ++iterator)
    ::printf("[%p -> %p]: %i\r\n", iterator, end, *iterator);
}
Why does it not iterate over the addresses of two & three?
 
there's no guarantee about the order of the memory addresses that that local variables are allocated into
 
@PeterT 😭
 
if you want an array, use an array
 
Yea, that'd be much smarter
Can't believe I didn't see the obvious solution there... I need rest
@PeterT There's no way to guarantee otherwise (just curious 🤔)?
 
nwp
That mix of C and C++ makes kittens cry :(
Maybe with a struct, but it's hacky and you need to language-lawyer a bit to be sure.
 
9:24 AM
@Lapys look up what your compiler, and platform have to say about it
different architectures can order their stack differently and most C compilers would respect the normal platform conventions around stack growth
but the standard doesn't give any guarantees about that and it would always be undefined behavior
 
https://chat.stackoverflow.com/transcript/message/50108403#50108403
Understandable ✌️
Thanks, man
 
Hey guys: what does the following piece of code do?
int func(int n, int k) {
    return ~(n^(1 << k));
}
 
bit inverts (n xor'd the kth bit)
 
1 << k
Is that same as
k >> 1?
 
no
 
9:35 AM
What's the difference?
 
one shifts 1 left k times
the other right shifts k, 1 times
 
Ah!! Right!
 
the xor would invert the k-th bit of n, so it's n inverted except for the k-th bit
 
Also, will n being equal to UINT_MAX make it any different>
*?
It shouldn't right?
 
10:14 AM
1
Q: Find the possible strings with a particular bit

d4rk4ng31The problem statement is as follows: To find the number of substrings with at least X bits set; given a string consisting of 0s and 1s Example: string: 1010 output: 2 The sample test case passes, but all the rest (hidden ones fail). Here is my code: #include <algorithm> #include <iostream> #inc...

Will anyone please take a look?
 
nwp
You can't clearly define the task, so it's impossible to know if an answer is correct. To make the question answerable you should define the rules clearly, even if they differ slightly from the actual task.
Is 12 the correct answer for the given example? The possible substrings are: 11, 110, 1100, 11001, 110011, 1100110, 11001101, 1001, 10011, 100110, 1001101, 11, 110, 1101, 101. Total substrings are 15 and unique substrings are 13. — srt1104 1 hour ago
You have to address that properly. "I have no idea whatsoever" is not sufficient.
 
 
1 hour later…
11:44 AM
Umm... (*ptr)[10] is an array of 10 pointers, right?
 
nwp
I think it's a pointer to an array of 10 elements.
 
Arrgh!!!!! There go my 4 points :( sob
 
nwp
Rip
 
No wait... that was negative marking... 5 points
howl
 
 
4 hours later…
3:27 PM
What is this referring at ?c45.Using in-class member initializers lets the compiler generate the function for you. The compiler-generated function can be more efficient.
 
nwp
struct S {
    int i = 42;
};
When you do S s; there is a function running that sets s.i to 42.
At least I think that's what they mean.
 
and that would be more efficient than actually writing the constructor and assign inside the constructor i - 42;?
 
nwp
That seems unlikely.
But in theory the compiler has full control over the function and doesn't need to pay attention to what you wrote.
 
maybe it s something related to the stack ?
or not
 
nwp
3:43 PM
I don't know why the stack would have to do anything with that.
 
I was thinking about inline
struct S {
    int i = f();
};
 
nwp
The difference is that in one case you have the compiler knowing to generate a default constructor and in the other case you have the compiler compiling an arbitrary constructor. It may be able to figure out that in this case the arbitrary constructor does the same as a default constructor and generates the same code, but it may also not do that analysis for compilation speed reasons or because it doesn't have a measurable effect in practice.
 
3:59 PM
a converting constructor is called converting because he converts different data types to it's enclosing class type ?
 
4:13 PM
Is there any rule that the initializer list of a constructor is runned befor it's block code ?
Its ok I found it
 
4:28 PM
Could you give me an example of an try catch block for initialiser list of a class? How would you actually use that in real life? I heard that after getting to catch block, all initialised objects calls their destructors so what could you do more than rethrow?
 
Do I understand correctly that std::map / std::unordered_map emplace() method only avoids copying the pair object, not the key and value objects?
I.e. it does not construct the value object in place while forwarding arguments to its constructor?
If so, what exactly is the point of using forwarding in std::map::emplace()?
 

« first day (1484 days earlier)      last day (1372 days later) »