« first day (2404 days earlier)      last day (437 days later) » 

9:49 AM
@JerryCoffin That's kinda genius.
An immoral solution would be to reinterpret_cast it to a pair of std::array<char, 10>* pointers (begin and end) and use std::sort on that.
Pretty sure it's UB, but ignoring that, I think it might work.
Of course, I would never do that. Because I'm not like that.
 
nwp
+3 C++ Credits, Winnie approves
 
 
5 hours later…
2:29 PM
Hello.. I have a question about arduino coding.. why when i write a code to and use Serial.print(); .. I do not see a window which shows the output of the code?
how to show that window in my computer?
how to do brother?
I want to see that window
to see the outputs
 
AAB
Hi all
#include <fstream>
#include <iostream>
int main() {
std::ofstream ofs("./testwrite");
ofs << "Hello World\n";
ofs.close();
if (ofs.good() == false) {
std::cout<< "\nError Occured during file write.\n";
return -1;
}
return 0;
}
I use gdb to step through the above code
at ofs.close() I delete the file
now after ofs.close() is executed and I step through the code
why does ofs.good() == false
not work
The way I see the stream should have fail or bad bit set as the data will not be sent from buffer to actual file on disk before the close, now that I have deleted the file the stream should be messed up Why do I still get a return 0
I compiled the above code on an RHEL 7.5 with c++11
 
@AAB because .good is deceiving because it's dependent on the last action, just check the stream using the operator bool
e.g. if(ofs)
 
AAB
that is successful as well
 
also did everybody get this question on some online test or something?
0
Q: strange thing in sequential file access

FomaniRecently, I am trying to write codes to get trained in sequential file access. I learned it well, but the issue is kinda stressing me out. I have a code that work 100%, and its task is "make a code that prints array elements inside a file", the text file name is "numric". #include <iostream> #inc...

also you don't need to call .close
the destructor will do that
5 messages moved from Lounge<C++>
@senshinakamora you need to connect to it using a serial terminal, there are tutorials online
 
AAB
if (ofs) -> get executed when I delete the file before close and when I dont tamper/touch the file.
 
2:40 PM
@AAB deleting the file doesn't do what you think it does. It may or may not cause a failure because of how the OS works
it's worth noting that if you're debugging you're looking at cached state
you never told the OS you needed to open the file exclusively
which also to be fair... isn't available via standard iostreams until c++23
so I guess the TL:DR is undefined behavior is undefined behavior
 
@Mgetz thank you very much
I wrote this code and connected my computer to arduino: but i dont see any output
void setup() {
Serial.begin(9600);
}

void loop() {
Serial.println(" Hello World ");
delay(2000);
}
 
2:57 PM
@senshinakamora what's the serial setting on both the Arduino and the computer? Serial doesn't auto negotiate, you need to pre-agree on baud rates etc
 
3:11 PM
For a static non-member function with separate declaration and definition, do I only need the static keyword in the forward declaration, or in the definition as well?
 
3:22 PM
@Mgetz thank you very much God bless you man.. It works now and understand how arduino works
 
AAB
3:36 PM
@Mgetz thanks
 
 
1 hour later…
4:59 PM
hi there!
 
nwp
5:45 PM
@VioletGiraffe It means something different in the definition, something you don't want, so don't put it in the definition.
 
 
3 hours later…
8:31 PM
what does it mean in the definition? I tried reading the cppref article about the static specifier, but it's terribly worded and laid out.
I can ask a question on the main site if you want to answer there.
 
nwp
It means that the definition is not available in other source files.
 
That's exactly what I need. What, then, does static mean in the forward declaration?
 
nwp
Wait, you said non-member function. I somehow ignored the non part.
I don't think it means anything in the declaration.
You would normally not declare things that you don't make the definition available for.
 
so it's always the static definition that makes it private?
 
nwp
private is something else, but yes.
 
8:35 PM
hidden, then
I usually didn't forward-declare internal functions, that's how I went 15 years of C++ programming without knowing how it works. But sometimes you want to forward-declare, and sometimes you may even need to.
 
nwp
Yeah, if they call each other you basically need to.
 
Right!
Thanks for the advice, going to fix that code now, where I didn't make the definition static :)
 
nwp
This says that functions declared have internal linkage. I'm not so sure anymore.
@VioletGiraffe So contrary to what I said you have to put it in the declaration, you may put it in the definition. At least it says so here. Sorry.
 
9:05 PM
@nwp Wow, thank you very much, really appreciate your spending the time to find the real answers! My bad for not finding it myself, although I did try (not hard enough).
 
 
2 hours later…
11:04 PM
hello... I'm hoping the 'BS::thread_pool' lib might help hasten my slow sequential program. However, I can't find a way to allow each thread to use its own dynamically-allocated 'working space' without having each task submitted to the queue alloc and free this space. It seems much more efficient to perform a single alloc/free for each thread and then have a task be able to determine which thread is executing it and use the workspace corresponding to that thread. Is anything like this possible?
 

« first day (2404 days earlier)      last day (437 days later) »