Re: ping source code
From: Dave Vandervies (dj3vande_at_csclub.uwaterloo.ca)
Date: 09/16/04
- Next message: Mark Piffer: "Re: union access"
- Previous message: Paul Hsieh: "Re: no lcm in standard library?"
- In reply to: wana: "ping source code"
- Next in thread: Kenneth Brody: "Re: ping source code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 16 Sep 2004 20:04:45 +0000 (UTC)
In article <bf0b47ca.0409161149.49bd3409@posting.google.com>,
wana <ioneabu@yahoo.com> wrote:
>I was reading through original source code of ping for some insight
>and was confused by unusual code.
>
>Entire listing available at:
>http://www.ping127001.com/pingpage/ping.html
>
>#include #include #include
>#include #include #include #include
>#include #include #include #include #include
>
>What does this mean? That is all of the #include's there are.
Without going to the URL you posted, this looks like a poor HTMLization
of source code, where the <> in `#include <foo.h>' get treated as tags
(and, since the browser doesn't recognize them, silently ignored).
>main(argc, argv)
>char *argv[];
>{
>
>That is how the main function starts. Is that legal?
Yes, but it's outdated.
In K&R C, this was how arguments were declared: names only in the argument
list, and types (defaulting to int if not specified) given between the
function name/argument list and the beginning of the function body.
Except for prototype-based type checking if you call a function after
it's been declared like this, this declaration is equivalent to:
--------
int main(int argc, char *argv[])
--------
which is the preferred form for newly written code. C90 still allows
the older type of declaration; I'm not sure about C99 - implicit int is
gone, but I'm not sure (and don't have a strong enough desire to know
to actually look it up) whether
--------
int main(argc,argv)
int argc;
char *argv[];
{
/*function body here*/
}
--------
is still allowed.
>There are structs that are network related that I don't know where
>they come from because of the lack of any recongnizable #include file.
If you dig into the HTML source, I'd expect you'll find the names of the
headers (see above). Most of them are probably unixisms rather than ones
defined by the C language, so if you have questions about them you'd be
likely to get better answers from comp.unix.programmer .
> The code is well organized and commented. I understand that this
>program is from 1982. Just for fun, I ran it through gcc and it
>generated a lot of errors, many of which are due to the lack of
>legitimate #includes. What does this all mean? Shouldn't the famous
>Ping code compile with gcc?
Possibly.
For one thing, what your browser is showing you is probably a mangled
version, not the original code. Also, the language has changed somewhat
since 1982, so a lot of what's in the code is no longer considered
good style, and it's quite possible that some of it is no longer legal.
(People who have worked with both K&R C and ANSI/ISO C will be better
able to comment on the differences.)
dave
--
Dave Vandervies dj3vande@csclub.uwaterloo.ca
More and more often I wish I didn't know anything about the Internet so
things like this wouldn't disturb me so much.
--Steve VanDevender in the scary devil monastery
- Next message: Mark Piffer: "Re: union access"
- Previous message: Paul Hsieh: "Re: no lcm in standard library?"
- In reply to: wana: "ping source code"
- Next in thread: Kenneth Brody: "Re: ping source code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|