tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: style change: explicitly permit braces for single statements



On 2020-07-13 17:52, Paul Goyette wrote:
    if (ch == t.c_cc[VINTR]) {
        ...do INTR processing...
    } else {
        if (ch == t.c_cc[VQUIT]) {
            ...do QUIT processing...
        } else {
            if (ch == t.c_cc[VKILL]) {
                ...do KILL processing...
            } else {
                ...etc
            }
        }
    }

For this, I would prefer

     if (ch == t.c_cc[VINTR]) {
         ...do INTR processing...
     } else if (ch == t.c_cc[VQUIT]) {
         ...do QUIT processing...
     } else if (ch == t.c_cc[VKILL]) {
         ...do KILL processing...
     } else {
         ...etc
     }

I would agree. That is a more readable way, I think.

In this case, perhaps even a switch might better, assuming that all of the t_c.cc[] are unique:

     switch (ch) {
     case t.c_cc[VINTR]) {
         ...do INTR processing...
         break;
     };
     case t.c_cc[VQUIT]) {
         ...do QUIT processing...
         break;
     }
     case t.c_cc[VKILL]) {
         ...do KILL processing...
         break;
     }
     ...etc

In which language would this be? It's not C at least... Syntax is slightly broken, but case values in C must be integer constant expression... But I agree it would be nice if C would allow more flexible options for the case values...

  Johnny

--
Johnny Billquist                  || "I'm on a bus
                                  ||  on a psychedelic trip
email: bqt%softjar.se@localhost             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol


Home | Main Index | Thread Index | Old Index