comp.lang.ada
 help / color / mirror / Atom feed
From: Warren <ve3wwg@gmail.com>
Subject: Ada Smileys in C++ lib Conversion
Date: Fri, 13 Aug 2010 07:20:16 -0700 (PDT)
Date: 2010-08-13T07:20:16-07:00	[thread overview]
Message-ID: <1a9b39b0-73f6-497c-a8f4-abf8129886ac@t20g2000yqa.googlegroups.com> (raw)

This week I've been busy porting last year's C++
version of my midi library over to Ada (now that I'm
using AVR-Ada).  As part of that effort, the Ada
compiler has discovered a few errors that were
lurking still in the C++ Arduino code.

In C++ I had defined:

/*
 * MC_CTL_CHG Control values :
 */
#define MC_CTL_ALLS_OFF 0x78 // All sounds off (120)
#define MC_CTL_RESET_C  0x79 // Reset controller
#define MC_CTL_LOCAL_C  0x80 // Local on/off
#define MC_CTL_ALLN_OFF 0x81 // All notes off
#define MC_CTL_OMNI_OFF 0x82 // Omni off request
#define MC_CTL_OMNI_ON  0x83 // Omni on request
#define MC_CTL_MONO_ON  0x84 // Mono on == POLY OFF
#define MC_CTL_MONO_OFF 0x85 // Mono off == POLY ON

But in Ada, when I declared:

    type Control_Type is new Unsigned_8 range 0..127;

and then coded:

    case Control is
        when MC_CTL_ALLS_OFF =>  -- ok
            ...
        when MC_CTL_LOCAL_C => -- oops
            ...

it immediately identified the value MC_CTL_LOCAL_C
(and others) as not fitting into the Control_Type's
valid range. In C++ a glaring error had gone
unnoticed:

#define MC_CTL_ALLS_OFF         0x78    // All sounds off (120)
#define MC_CTL_RESET_C          0x79    // Reset controller
#define MC_CTL_LOCAL_C          0x7A    <==== not 0x80
#define MC_CTL_ALLN_OFF         0x7B    <==== not 0x81..

Non commands in midi should not have had bit 7 set.
So as it was coded, those control messages would
never have been processed in the C++ lib.

I'm always smiling when I convert code from C/C++ to
Ada. In code of any significant size, Ada always
discovers problems that went unnoticed in C/C++.

Warren



             reply	other threads:[~2010-08-13 14:20 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-13 14:20 Warren [this message]
2010-08-13 15:06 ` Ada Smileys in C++ lib Conversion Yannick Duchêne (Hibou57)
2010-08-13 16:53 ` Anh Vo
2010-08-14  1:36   ` Warren
2010-08-14  9:52     ` Georg Bauhaus
2010-08-14 10:57     ` Brian Drummond
2010-08-14 20:34       ` Maciej Sobczak
2010-08-14 21:01         ` Dmitry A. Kazakov
2010-08-15  1:16         ` Brian Drummond
2010-08-15 10:04           ` Maciej Sobczak
2010-08-16 12:08             ` Brian Drummond
2010-08-16 12:13               ` Georg Bauhaus
2010-08-16 12:30             ` Brian Drummond
2010-08-16 12:39               ` Maciej Sobczak
2010-08-16 21:39                 ` Brian Drummond
2010-08-16 22:53                   ` Robert A Duff
2010-08-24 10:12           ` David Thompson
2010-08-30  9:51             ` Brian Drummond
2010-08-16 14:54       ` Warren
2010-08-16 20:27         ` Maciej Sobczak
2010-08-17 12:57           ` Warren
2010-08-17 13:37             ` Maciej Sobczak
2010-08-17 15:07               ` Georg Bauhaus
2010-08-18 17:31               ` Warren
2010-08-24 10:12             ` David Thompson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox