How to Convert 1998 morse.c to 2006

Discussion in 'C Programming' started by humanmutantman@yahoo.com, Jul 16, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. tmp123 Guest

    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 ) {
    tmp123, Jul 16, 2006
    #2
    1. Advertising

  3. Tim Prince Guest

    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.
    Tim Prince, Jul 16, 2006
    #3
  4. 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) <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.
    Keith Thompson, Jul 16, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ruby Quiz

    [QUIZ] Morse Code (#121)

    Ruby Quiz, Apr 20, 2007, in forum: Ruby
    Replies:
    25
    Views:
    307
    John W. Kennedy
    Apr 26, 2007
  2. Mark Day
    Replies:
    0
    Views:
    102
    Mark Day
    Apr 22, 2007
  3. MenTaLguY
    Replies:
    1
    Views:
    83
    MenTaLguY
    Apr 24, 2007
  4. Brian Krahmer

    [QUIZ][SOLUTION] Morse Code (#121)

    Brian Krahmer, Apr 25, 2007, in forum: Ruby
    Replies:
    0
    Views:
    84
    Brian Krahmer
    Apr 25, 2007
  5. Ruby Quiz

    [SUMMARY] Morse Code (#121)

    Ruby Quiz, Apr 26, 2007, in forum: Ruby
    Replies:
    2
    Views:
    129
    James Edward Gray II
    Apr 26, 2007
Loading...

Share This Page