« first day (1807 days earlier)      last day (1036 days later) » 

mr5
1:24 AM
Do you guys know if ngrok can expose local router to the public internet?
 
 
8 hours later…
9:25 AM
Here is a code snippet which could be successfully compiled, whereas encountering running error(i.e: Error on receive: Element not found):
void TcpClient::read()
{
boost::asio::async_read_until(socket_, boost::asio::dynamic_buffer(m_vector_of_chars_read_buffer, m_vector_of_chars_read_buffer.size()),
"\n",
boost::bind(&TcpClient::handle_read, this, _1));
}

Some hint:
This code snippet works well:
void TcpClient::read()
{
boost::asio::async_read_until(socket_, boost::asio::dynamic_buffer(m_vector_of_chars_read_buffer, 1*1024*1024),
Where goes wrong? Could somebody shed some light on this matter?
Maybe, I found how to solve it. It should be m_vector_of_chars_read_buffer.capacity() other than m_vector_of_chars_read_buffer.size().
 
10:03 AM
Which C++ compilers have supported C++20 module?
 
@nwp: Thank you very much!
 
11:07 AM
3 messages moved from Lounge<C++>
 
12:00 PM
I don't understand why 3 messages moved from Lounge<C++>. I did not post to Lounge<C++>.
what is the left pointing arrow for?
 
12:12 PM
@TheShortestMustacheTheorem because you did
I moved them
 
@Mgetz I did not post to the lounge.
Hmm... something wrong...
 
I can't move messages from channel that were never posted
and the log indicates A) they were moved
B) you posted them
C) I moved them
The arrow indicates exactly which messages were moved
 
@Mgetz: OK. Thank you!
 
12:32 PM
in addition when moved messages get removed from the log of the other channel
 
 
2 hours later…
2:26 PM
https://pastebin.com/PB5TL0FL <<this is my code
https://pastebin.com/shKtkEEC <<this is the output

so i entered "zzzzzzzz" as an input and it displays it multiple times
how can i get rid of this?
 
@Praveen well you're not doing a few things... you need to A) ensure that your buffer is 1 larger than your expected input B) zero initialized.
othewise you risk UB
 
whats UB?
 
undefined behavior
remember C strings are zero terminated
you're overwriting that termination with a non-zero character
or more importantly... never initializing the buffer regardless
 
ok so this is my first program in c i have no idea what you are saying
 
even if I do your original input... it's going to cause issues where the string isn't terminated coliru.stacked-crooked.com/a/ac686f662ad95112
also your array c isn't null terminated so it won't print properly
and will instead cause undefined behavior
 
2:48 PM
ok so '\0' terminates a string?
 
Yes, normally you don't declare a string in C using an array
you'd do const char* foo = "bar"; and the compiler implicitly adds the '\0' for you
for a writable buffer you'd declare it as one larger than you intend and the either memset it to zero or do an initializer like I did
 
@Mgetz i tried this it works but it gives me a warning
oh ok
 
see how I changed c?
and yet it works fine
 
oh got it
 
side note: scanf for console input is considered insecure
 
2:53 PM
then what shld i use?
and why is it insecure?
 
so the way you're using it isn't as bad, but if you don't have that limit on input characters you can easily overwrite your input buffer
and rule number 1 of coding securely is never trust anything from anyone else
 
ok so how to make it accept infinite characters ?
 
you can't
unless you do getchar in a loop and adjust your buffer
normally when you want string input you can puts your prompt and then do an fgets on your buffer
so that can't possibly overwrite the entire buffer
because it only ever gets 10 characters from stdin
use scanf when you need much more formatted input like a number
technically I should be checking return values too...
 
oh ok
 
so one other major callout... when printing a value the printf specifier MUST be correct. So for example for size_t it should be zu for example otherwise A) you could have serious stack corruption or undefined behavior B) your program probably won't work
this is because printf is a "var args" function, which means it passes parameters in a special way. The format specifiers tell the method how to go and get those arguments.
if the specifiers are wrong then it could do something weird and cause issues.
 
3:15 PM
what is zu ?
 
it's the c11 specifier for size_t which is unsigned long long in most implementations but isn't guaranteed to be
 
oh ok
 
So the other place you get helpful macros for this sort of thing is in stdint.h if you're using the fixed width types
 
yea ok
 
 
4 hours later…
7:41 PM
anybody know of a gcc intrinsic to get the upper/lower half of a 32 bit number?
 
like just with a shift and a mask?
 
So basically, (unsigned short)(some_uint_32 >> 16)
mask is probably extra
 
7:54 PM
for the upper half yeah
and a mask if you want to get the lower half
 
you can just cast
(unsigned short)(some_uint_32)
 
I don't even know how narrowing casts work ^^'
 
It works hard!
 
value casts are supposed to preserve the value, but for a value too big to represent I guess that it only discards the higher bits?
 
11 messages moved from Lounge<C++>
 

« first day (1807 days earlier)      last day (1036 days later) »