D
Default User
smnoff said:I am a little confused on the WHILE loop at line 511 shown below(or
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes.
Brian
smnoff said:I am a little confused on the WHILE loop at line 511 shown below(or
In my shop, you'd format it like this, or maybe you'd be happier
elsewhere
while ((c = *++s2) == *s1++ && c);
pete said:ITYM
while ((c = *++s2) == *s1++ && c) {
;
}
This is my version of strstr:
Flash said:I think you missed something here.
Yeah. And I totally refuse to buy any argument I've ever heard
against using brackets on control structures, even when they are only
one-statement blocks.
In my shop, you'd format it like this, or maybe you'd be happier
elsewhere
strstr(const char *as1, const char *as2)
{
const char *s1,
*s2;
const char *tptr;
char c;
s1 = as1;
s2 = as2;
if (s2 == NULL || *s2 == '\0') {
return ((char *) s1);
}
c = *s2;
while (*s1) {
if (*s1++ == c) {
tptr = s1;
while ((c = *++s2) == *s1++ && c);
if (c == 0) {
return ((char *) tptr - 1);
}
s1 = tptr;
s2 = as2;
c = *s2;
}
}
return (NULL);
}
ozbear said:Ugh!
jmcgill said:I didn't write it. I only formatted it.
Don't tell me you preferred the original, with no indents,
and overly economical braces.
jmcgill said:I think all I did was run the code through indent and maybe added a pair
of brackets.
Your questions all need to be directed to someone who codes for the open
version of the string library for Solaris, which is where I was led to
believe this code originated.
Chris said:jmcgill said:I didn't write it. I only formatted it.
Don't tell me you preferred the original, with no indents,
and overly economical braces.
One can think that both are unnecessarily ugly.
[And I've heard no convincing argument for using brackets on
control structure arguments when they are only one-statement
blocks.]
Chris said:jmcgill said:ozbear wrote:
Ugh!
I didn't write it. I only formatted it.
Don't tell me you preferred the original, with no indents,
and overly economical braces.
One can think that both are unnecessarily ugly.
[And I've heard no convincing argument for using brackets on
control structure arguments when they are only one-statement
blocks.]
Out of curiousity, what arguments have you heard?
smnoff said:So I got to ask, why does code get written like this to begin with?
Especially since this is library code? Job Security? Just because they can?
Neat trick?
Jacob Navia posted the gcc source code for strstr here a little while
ago. Now *that* code is hairy. But at least they justify it by being
fairly fast. Now of course, why none of this code is commented is
beyond me. It probably should be.
Chris said:Chris said:jmcgill wrote:
ozbear wrote:
Ugh!
I didn't write it. I only formatted it.
Don't tell me you preferred the original, with no indents,
and overly economical braces.
One can think that both are unnecessarily ugly.
[And I've heard no convincing argument for using brackets on
control structure arguments when they are only one-statement
blocks.]
Out of curiousity, what arguments have you heard?
That not using brackets means that when additional statements
are added to the controlled statement, the adder won't put
in the brackets and the code will be broken.
One should be consistent.
The local style guide says so.
Chris Dollin wrote:
.... snip ...
Thank you, I appreciate the reply.
Do your comments mean that you've never experienced someone adding
a line of code and forgetting to add the braces?
Thank you, I appreciate the reply.
Do your comments mean that you've never experienced
someone adding a line of code and forgetting to add
the braces?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.