hu************@yahoo.com writes:
I stumbled across morse.c located at
http://c2.com/ward/morse/teach/morse.c
When I attempted to compile it with gcc 4.1.0 I get the following
errors:
morse.c:208: error: conflicting types for 'send'
morse.c:208: note: an argument type that has a default promotion
can't match an empty parameter name list declaration
morse.c:165: error: previous implicit declaration of 'send' was
here
Lines 208-216 are:
send(char code) {
register element;
do {
element = dit;
if (isdah(code)) element *= 3;
beep(TONE_ON, element);
beep(TONE_OFF, dit);
} while ((code >>= 1) != 1);
}
Can someone help me update morse.c to the 21st century? Thanks.
That's (mostly) some very old-style code, but when I compiled it
myself with gcc 4.1.0 with no options, I didn't get any errors (once I
added definitions for dit, TONE_ON, and TONE_OFF). The biggest
problem I see in the fragment you posted is the use of implicit int.
Change
send(char code)
to
void send (char code)
(With no type specified, it defaults to int, but since it doesn't return
a value it should be void, which didn't exist in very old C).
And change
register element;
to
register int element;
or just
int element;
But since gcc accepts implicit int by default, this isn't really
necessary.
The real problem is that there's a call to send() (on line 165) before
the compiler has seen a declaration of it (on line 208) -- something
not shown by the code fragment you posted. I was able to avoid this
problem by adding a declaration just before main():
*** morse.c 1998-08-07 10:35:28.000000000 -0700
--- morse.c.new 2006-07-16 15:16:44.000000000 -0700
***************
*** 81,86 ****
--- 81,88 ----
{'S', 010, BAD}, {'I', 004, BAD}, {'T', 003, BAD}, {'E', 002, BAD},
};
+ int send(char code);
+
/*** main - teach morse code
/*
/* This program repeatedly selects a letter and teaches it to the
With that change, it compiles cleanly -- but it doesn't link on my
system, because it refers to a number of symbols that don't exist:
beep pc prc resp ticks tod
Possibly these are provided by other source files.
That should be enough to get it to compile and link, but it's still
poor style by modern standards. There are still a blortload of calls
to undeclared functions; there should be header files for all these
functions, which should be #included by anything that needs them.
Getting the whole thing to compile and link without warnings with
gcc -std=c99 -pedantic -Wall -W -O3
could be an interesting exercise. (Or replace -std=c99 with -ansi if
you prefer.)
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.