Sujet : Re: Command Languages Versus Programming Languages
De : cross (at) *nospam* spitfire.i.gajendra.net (Dan Cross)
Groupes : comp.unix.shell comp.unix.programmer comp.lang.miscDate : 22. Nov 2024, 20:05:42
Autres entêtes
Organisation : PANIX Public Access Internet and UNIX, NYC
Message-ID : <vhqkm6$7dv$1@reader2.panix.com>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
87h67zrtns.fsf@doppelsaurus.mobileactivedefense.com>,
Rainer Weikusat <
rweikusat@talktalk.net> wrote:
cross@spitfire.i.gajendra.net (Dan Cross) writes:
>
[...]
>
In any event, this seems simpler than what you posted:
>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
>
int
main(int argc, char *argv[])
{
if (argc != 2) {
fprintf(stderr, "Usage: matchd <str>\n");
return EXIT_FAILURE;
}
>
for (const char *p = argv[1]; *p != '\0'; p++)
if ('0' <= *p && *p <= '9')
return EXIT_SUCCESS;
>
return EXIT_FAILURE;
}
>
It's not only 4 lines longer but in just about every individual aspect
syntactically more complicated and more messy and functionally more
clumsy.
That's a lot of opinion, and not particularly well-founded
opinion at that, given that your code was incorrect to begin
with.
This is particularly noticable in the loop
>
for (const char *p = argv[1]; *p != '\0'; p++)
if ('0' <= *p && *p <= '9')
return EXIT_SUCCESS;
>
the loop header containing a spuriously qualified variable declaration,
Ibid. Const qualifying a pointer that I'm not going to assign
through is just good hygiene, IMHO.
the loop body and half of the termination condition.
I think you're trying to project a value judgement onto that
loop in order to make it fit a particular world view, but I
think this is an odd way to look at it.
Another way to loop at it is that the loop is only concerned
with the iteration over the string, while the body is concerned
with applying some predicate to the element, and doing something
if that predicate evaluates it to true.
The other half then
follows as special-case in the otherwise useless loop body.
That's a way to look at it, but I submit that's an outlier point
of view.
It looks like a copy of my code which each individual bit redesigned
under the guiding principle of "Can we make this more complicated?", eg,
Uh, no.
char **argv
>
declares an array of pointers
No, it declares a pointer to a pointer to char.
(as each pointer in C points to an array)
That's absolutely not true. A pointer in C may refer to
an array, or a scalar. Consider,
char c;
char *p = &c;
char **pp = &p;
For a concrete example of how this works in a real function,
consider the second argument to `strtol` et al in the standard
library.
and
>
char *argv[]
>
accomplishes exactly the same but uses both more characters and more
different kinds of characters.
"more characters" is a poor metric.
- Dan C.