« first day (1359 days earlier)      last day (1485 days later) » 

4:06 AM
Why gdb info locals shows all variables inside a function when the program has not executed till the line of initialization?
 
 
4 hours later…
7:51 AM
What is the difference between std::thread and std::async?
 
nwp
Mostly that the first represents a thread and the second represents a value to be determined.
 
8:05 AM
but future can be used without async
 
nwp
Yes. And std::async can be used without threads.
 
Does the way async and promise work together, is basically: async launches a thread which does work until it gets stuck because it doesn't know something, and then when promise.set_value() is called, the thread can continue with the given information. Is that the gist?
 
nwp
Hmm, kinda sorta. The thread doesn't normally get stuck and it calls promise.set_value. The user of std::async may have to wait when getting the value out of the future. Also the thread is optional.
 
8:53 AM
When passing a lambda expression to async, if the lambda expression takes an argument by reference, would you use ref() ? In this case a std::vector<bool> is being passed by reference
 
nwp
std::async takes ownership of the parameters, so taking a reference should be fine. Beware of data races.
 
This is what I don't get. Everyone said to use async to replace a thread, but what's the difference if there's still the need to protect against a data race? stackoverflow.com/questions/60896525/…
 
you asked "how can I avoid creating and destroying threads" and implementations of std::async can be made without re-creating a thread each time
you didn't ask "how can I avoid data races"
 
nwp
You can do everything with std::thread you can do with std::async and the other way around. The reason why you use one over the other is convenience. std::async is really good for "Compute this value later and give it to me". Expressing "give it to me" with std::thread is more annoying because you have to manually screw with promises and futures, but it can be done.
 
@PeterT that is right, thanks for reminder
 
9:32 AM
@PeterT gm, I found yesterday something a little bit wired and I couldn't find anything online to explain it. The link is the same https://en.cppreference.com/w/cpp/language/enum, the example is from the 4th code box.

enum access_t { read = 1, write = 2, exec = 4 }; // enumerators: 1, 2, 4 range: 0..7
contains 0b0001, 0b0010, 0b0100 and they say that now a 7 which is 0b0111 in binary can be converted to that enum without undefined behaviour. How does it comes?
 
> if it would fit in the smallest bit field large enough to hold all enumerators of the target enumeration

the smallest bitfield that holds "4" would be int b:3;
rather "unsigned int b: 3" I guess
 
9:49 AM
so if enum access_t { read = 1, write = 2, exec = 5Î , the smallest bitfield that holds "5" would be int b:4 , and the range of the enum becomes 0...15?
 
yes, that's how I read that definition
oh, wait you need exec=8 at least
5 still fits in 3 bits
0b101
 
10:21 AM
I create an Assembly code file called: asm1.asm
I execute the command: nasm -f elf32 -o asm1.o asm1.asm
Then I execute this: ld -m elf_i386 -g -o asm1 asm1.o
Then I try to debug with: gdb asm1 or gdb ./asm1
In both cases gdb just outputs: (No debugging symbols found in asm1)
Note: running asm1.asm (./asm1) works and outputs "Hello world"

Here is the code for asm1.asm:
section .text
global _start
_start:
mov edx,len
mov ecx,msg
mov ebx,1
mov eax,4
int 0x80
mov eax,1
So how can I debug my Assembly program?
 
why do you need debug symbols for asm :P
just look at the assembly listing
 
Im really new to this xD
Hmm how do I do that with gdb
I want to be able to debug my Assembly code, I'm trying to learn it and I want to see the registers and memory
 
layout asm
should show you the disassembly
 
I should write that after running gdb ./asm1 ?
in gdb I mean
 
yeah, in the gdb command line
 
10:24 AM
Cannot access memory at address 0x804901d
got this
 
can you set a breakpoint on _start and run to there first?
so
> break _start
> r
or was it "g" for go
 
When I try break _start it says "No symbol table is loaded"
 
hm, not sure. Google tells me adding "-F dwarf -g" to the nasm flags might do something
 
nasm:fatal: unrecognized debug format `dwarf' for output format `bin'
type `nasm -h' for help
 
hm, weird, did you keep the rest of the flags the same?
 
10:36 AM
well I changed the -f to -F, wasnt I supposed to do that? I also replaced elf64 with dwarf
so from: nasm -f elf64 asm1.asm
I did: nasm -F dwarf asm1.asm
 
nah, you need both
 
oke so I did: nasm -f elf64 -F dwarf asm1.asm
and it didnt output any error
 
and the -g
 
ooh ok
Same story all over again
No symbol table loaded
layout asm also doesnt work
I did: nasm -f elf64 -F dwarf -g asm1.asm
Does it work on your machine?
 
let me see
yeah I can set the breakpoint, but the program segfaults :P
 
10:54 AM
hmm can you please send me a command by command what you did? For some weird reason, I cannot set the breakpoint
 
I copy pasted your commands
 
and its weird it segfaults as it actually runs fine xD
@PeterT haha
Can it be machine specific?
 
the breakpoint shouldn't but the actual running is machine specific yes
seems like I just can't run it because wsl doesn't support elf32
 
hmm
so you cant even do ./asm1 ?
It's weird how you can set a breakpoint but cant run the program, whilst its reversed for me...
 
well there's all kinds of different version we can have of nasm,ld,gdb and the whole OS we're running
 
11:05 AM
@PeterT oh, Im running in a VM on Ubuntu 19.04
@PeterT Yeah I see... idk what to do xD I looked up questions on SO related to this and I tried a few things but no luck
 
In below program not sure how my boolean attribute is getting modified when I use objects instead of pointers:

#include <iostream>
#include <map>

using namespace std;

class Node
{
private:
map<char, Node> mymap;
bool test;

public:
Node():test(false){}

bool getTest()
{
return test;
}

void setTest()
{
test = true;
}

map<char, Node>& getMap()
{
return mymap;
}
};

class A {
private:
Node* root;

public:
A()
{
root = new Node();
}

void insert(string word)
{
Node* crawler = root;
for (char ch : word)
 
@PeterT I guess I will have to use print statements... Is there a way to print registers and memory?
 
11:26 AM
@mSatyam it's this line crawler = crawler->getMap()[ch];
The copy source on the right is part of the memory you assign to one the left
Node temp = crawler->getMap()[ch];
crawler = temp;
//this works for me
 
@PeterT So what could be the reason this line "crawler = crawler->getMap()[ch];" not working...didn't get much
Yes those new lines works for me as well but Just wanted to know what difference it created internally
Why an extra temp Node is required, and why I am so dumb
 
you essentially do
crawler.mymap = crawler.mymap[a].mymap;
inside the implementation of operator= of the map, the memory of mymap is deallocated first and then read again to assign the value
 
11:44 AM
Hey guys :), I have another C++ (beginer?) Question ;)
My application, which I develop in Qt, consists of the following processes: Using a GUI, I search for Bluetooth devices, select a device, a directory and then click on "Transfer data". Then you get to another view, where the data is plotted and at the same time displayed numerically in a table. In the background, the data is continuously written to a file locally on the PC. The question now is, where does it make sense to incorporate threads?
 
But how map is that affecting bool attribute. I see there is a chain of Copy Constructors being called....looking further
 
@mSatyam you are reading from memory that is no longer valid, you can use something like valgrind to debug that better if you want to see where exactly it's wrong
 
nwp
@SpaceToon That sounds like you don't need or want any threads.
 
Hmm, I thought maybe putting the numerical display and file-writing to another thread that the plotting would be better for the CPU or something like that
than the plotting*
 
nwp
That shouldn't cost significant CPU time. I would expect the program to run at below 1% CPU without even trying.
You're bottlenecked at the Bluetooth connection,
Maybe if you have like over 10MB per second it might make sense.
 
11:50 AM
Oh okay, it is even Bluetooth Low Energy, which means lower data rate - so you might be right
 
there is no fast bluetooth
 
12:09 PM
Thank you guys
 
 
6 hours later…
6:28 PM
does smart pointer exists or is just a concept of wrapping a class over a normal pointer?
 
6:45 PM
Hey all, so I'm trying to pass an XML client to a listener via a client, the problem is, is that with formatted XML, it reads the carriage return and says "okay that's end of input" and so the listener only receives the first line of my XML document. How can I get around this?
 
 
1 hour later…
7:58 PM
what is a meaning of pointer to object in c?
 
 
1 hour later…
9:10 PM
@sunil Well, a pointer that points to an instance of a class
 
9:32 PM
if I want to overload ++ operator Class obj, obj++ why should the prototype look like operator++(int) and not operator++() without parameters?
 
@CătălinaSîrbu; haha sorry no idea, but @PeterT should be able to help
 
@CătălinaSîrbu That is just a language rule to distinguish between overloading pre-increment and post-increment operators.
 
so i can just put int a and never use it ?
just asa distinguish sign, right?
 
@CătălinaSîrbu Yup, just a dummy parameter
 
@ArdentCoder thank you
 
 
1 hour later…
11:10 PM
why I dont get any erros in this code?
#include <iostream>
#include <string>

using namespace std;

class X
{
public:
string n;

X(string s) : n(s) {}

void operator() (X x)
{
cout << x.n;
}
};
int main(void)
{
X x("a"),y("b");
x(y);
y(x);

return 0;
}
 

« first day (1359 days earlier)      last day (1485 days later) »