How to Convert 1998 morse.c to 2006

H

humanmutantman

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.
 
T

tmp123

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 ) {
 
T

Tim Prince

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.
 
K

Keith Thompson

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.)
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top