Sometimes I wonder about the perl source code. So I was looking at what Perl_looks_like_number actually does. And the code is the following:
I32 Perl_looks_like_number(pTHX_ SV *sv) { register char *sbegin; STRLEN len;Mmmm, funky backwards indenting and amusing comment with two returns in a row...
if (SvPOK(sv)) { sbegin = SvPVX(sv); len = SvCUR(sv); } else if (SvPOKp(sv)) sbegin = SvPV(sv, len); else return 1; /* Historic. Wrong? */ return grok_number(sbegin, len, NULL); }
Not quite. Single statement blocks in C don't need surrounding braces, so the two returns there do make sense. The first one is associated with the else branch. As the reverse indenting attempts to make clearwith two returns in a row
Re:Blocks in C
yDNA Barak on 2004-02-02T12:56:07
Wait a minute. Okay, I'm no C jockey, but doesn't this mean the final return statement could never be reached?I've got my K&R right here, buddy!if (SvPOK(sv)) {
sbegin = SvPVX(sv);
len = SvCUR(sv);
}
else if (SvPOKp(sv))
sbegin = SvPV(sv, len);
else
return 1;/* Historic. Wrong? */
return grok_number(sbegin, len, NULL);;) Re:Blocks in C
davorg on 2004-02-02T13:02:59
No. The "return grok_number" still gets called if either SvPOK or SvPOKp return a true value.
For example, if SvPOK returns true, then sbegin and len are set and the program execution moves to the first statement _after_ the if/else block, i.e. the "return grok_number".
It's been a loong time since I wrote C, and my memory could be fading, but I'm pretty sure I'm right here.Re:Blocks in C
yDNA Barak on 2004-02-02T13:07:31
Ah, duh. Got it. Just like what I'd want perl to do. Good thing I don't mess with C much.
It looks to me like the source uses tab characters to indent code, and your editor shows it as 3 spaces instead of the traditional 8.
Tabs must die.
schwern on 2004-02-03T00:41:04
That is all.