3 ms·
I don't write C at all and the *++argv thing is obvious to me? Look at the pointer of argv, then look at its sibling?
by cyberbanjo 4y ago
I don't write C at all and the *++argv thing is obvious to me?
Look at the pointer of argv, then look at its sibling?
- pm215 4y agoThat's not what the expression does. It means "first increment argv (so it points to the thing at index 1 in the original argv array); then dereference it". (Contrast *argv++, which dereferences at the initial pointer value, and then increments the pointer variable.) A lot of that sort of pointer pre/post-increment/decrement comes down to "idiomatic ways to write things", which are easier to read when you've seen them a hundred times before. Personally for this specific case I'd have split the increment to its own line -- because conceptually the job that is doing is "skip over the program name in argv[0]", whereas everything else in the if() is the entirely separate "see if the next argument, if any, is '-n'".
- HKH2 4y agoAccording to the code, will the nflag work if you put it at the end? (e.g. 'echo hello world -n')
- arexxbifs 4y agoNope, and that's by design. "The BSD echo checks the first argument for the string -n which causes it to suppress the newline that would otherwise follow the final argument in the output." https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/e...