468,484 Members | 1,704 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

How to Convert 1998 morse.c to 2006

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.

Jul 16 '06 #1
3 3301

hu************@yahoo.com wrote:
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);
}
Change line 165 to:

void send ( char );

and line 208 to:

void send ( char code ) {

Jul 16 '06 #2
hu************@yahoo.com wrote:
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);
}
The diagnostics appear to say that no prototype for send() is visible, e.g.
void send(char);
which should come before any use of send(). It looks like there is a
lot of playing fast and loose with default typing, in pre-K&R style.
You may need to crack a C textbook, maybe re-write it without looking at
the old code.
Jul 16 '06 #3
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.
Jul 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by WebM¤nkey | last post: by
5 posts views Thread by Peter van Oord van der Vlies | last post: by
2 posts views Thread by kirke | last post: by
2 posts views Thread by ahnie05 | last post: by
2 posts views Thread by mahen6 | last post: by
Thekid
9 posts views Thread by Thekid | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.