473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 3527

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: WebM¤nkey | last post by:
Hi folks Just found that the mktime function returns a negative value when the date is 26 march 2006 with 0 hours, 0 seconds and 0 minutes. Is this a documented problem ? Any suggestions ?
41
by: Petr Jakes | last post by:
Hello, I am trying to study/understand OOP principles using Python. I have found following code http://tinyurl.com/a4zkn about FSM (finite state machine) on this list, which looks quite useful for...
5
by: Peter van Oord van der Vlies | last post by:
Hello, I have a field that have wrong typed data, for example the date in that field looks like 20-04-2006 (day month year) and i need to convert it to 2006-04-20. What is a possible way to...
2
by: kirke | last post by:
Hi, I have a datetime column named dtDateTime. its format is "Oct 27 2006 12:00:00 " I want to group by only date part of it and count my code is $sql1="SELECT ...
2
by: ahnie05 | last post by:
I'm given a final project of my professor and it is about THE MORSE CODE. How can convert a string character into its corresponding mores code.. Can you please send me its simple code? Thanks!...
2
by: mahen6 | last post by:
hi there, i am doing a morse code project in vb6.0 .. my project is to convert an alphabet to morse code and from morse code to alphabet ,, i have already did the vb 6.0 coding for alphabet...
0
by: binh2807 | last post by:
Hi! Psl help me I have a morse application. I want to convert morse text file into wav file or mp3 file for me play it by windows media player. How can i do it. Thanks.
9
Thekid
by: Thekid | last post by:
I'm trying to figure out how to have a text file with a word in morse code in it and have my program decode it and print it out. I've managed to do the opposite where a word is in the text file and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.