« first day (1221 days earlier)      last day (1623 days later) » 

nwp
10:57 AM
4 messages moved to Trash can
struct {
	const char *settings_key;
	const char *default_settings_key;
	void (UI_container::*signal)();
} actions_data[] = {
	{Globals::confirm_key_sequence_key, Globals::default_confirm_key_sequence_key, &UI_container::confirm_pressed},
	{Globals::skip_key_sequence_key, Globals::default_skip_key_sequence_key, &UI_container::skip_pressed},
	{Globals::cancel_key_sequence_key, Globals::default_cancel_key_sequence_key, &UI_container::cancel_pressed},
};
for (auto &action_data : actions_data) {
	//use action_data.stuff
This code feels bad because the struct declaration seems unnecessary and it's bloated to the point where one questions if copy/pasting the loop contents isn't just better.
 
tuple it?
 
nwp
Maybe once for constexpr is available or whatever syntax they use now. I don't know how to write it in a readable way without that.
And even with it'll be confusing. auto data = {{1, 2, "hi"}, {3, 4, "world"}}; should just work.
 
 
5 hours later…
3:46 PM
This poll usage is new to me..
#include <stdio.h>
#include <poll.h>

int main(void)
{
    struct pollfd pfds[1]; // More if you want to monitor more

    pfds[0].fd = 0;          // Standard input
    pfds[0].events = POLLIN; // Tell me when ready to read

    int num_events = poll(pfds, 1, -1);

    char buf[256];

    if (num_events == 0) {
        printf("Poll timed out!\n");
    } else {
        int pollin_happened = pfds[0].revents & POLLIN;

        if (pollin_happened) {
            fgets(buf, sizeof buf, stdin);
            printf("%s\n", buf);
poll allows me to input before it meets any scanf, fgets like function.
Wow :)
 
4:10 PM
yeah the standard streams are defined to be file descriptors 0,1,2 for stdin, stdout and stderr resp. on starting the program
 
@ratchetfreak Yes I know the 0,1,2 file descriptor part. It's about that I can start to input at int num_events = poll(pfds, 1, -1);, before any scanf like function.
In my old impression, "programe block -> start input -> scanf read stdin" is a complete/continuous procedure.
But now it tells me that "program block -> start input" and "scanf/fgets ... read stdin" can be separate.
 
 
2 hours later…
6:08 PM
@Rick If you really want strange, there was a while (before nanosleep) when poll was the only thing that let you sleep for less than a second at a time, so people would put a thread to sleep for, say, 20 ms by creating a temporary file, then polling it for data to read with a 20 ms timeout.
 
ggg
Coming from Java, i tried to pass a char array (socket receive buffer) as a return val from a function in my network class back to my main class. As i understand it, this does not work because 1) you cannot pass arrays, only references or pointers 2) if the array was declared in the function it would no longer exist when exiting the function. So how would you titans of computer science go about this?
 
@ggg well the closest to a java array is std::vector which is passable. What you're referring to as an 'array' is just a pointer
1 message moved from Lounge<C++>
1 message moved from Lounge<C++>
 
ggg
Is that standard practice of doing it? in other words, every time you need to transfer data between classes you have to convert it to a vector? and then back to say char[] at the receiving end
 
6:23 PM
@ggg no you'd use the appropriate medium, which might be std::string_view for example
 
ggg
alright, gotcha, only used std::string but i see your point
 

« first day (1221 days earlier)      last day (1623 days later) »