From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3190 invoked by alias); 1 Sep 2010 19:59:47 -0000 Received: (qmail 3181 invoked by uid 22791); 1 Sep 2010 19:59:47 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 01 Sep 2010 19:59:41 +0000 Received: (qmail 15242 invoked from network); 1 Sep 2010 19:59:38 -0000 Received: from unknown (HELO orlando.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 1 Sep 2010 19:59:38 -0000 From: Pedro Alves To: Jan Kratochvil Subject: Re: [patch 1/9]#2 Rename `enum target_signal' to target_signal_t Date: Wed, 01 Sep 2010 20:06:00 -0000 User-Agent: KMail/1.13.2 (Linux/2.6.33-29-realtime; KDE/4.4.2; x86_64; ; ) Cc: gdb-patches@sourceware.org, Joel Brobecker , Eli Zaretskii , Mark Kettenis References: <201009012007.55983.pedro@codesourcery.com> <20100901191843.GA27558@host1.dyn.jankratochvil.net> In-Reply-To: <20100901191843.GA27558@host1.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201009012059.36696.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-09/txt/msg00057.txt.bz2 On Wednesday 01 September 2010 20:18:43, Jan Kratochvil wrote: > On Wed, 01 Sep 2010 21:07:55 +0200, Pedro Alves wrote: > > I wonder if switching on "-Wc++-compat" wouldn't catch these (at > > least with recent enough gccs) and be more productive than > > switching to a struct. /me ducks. >=20 > I wanted to argue with this great point myself but during my tests (gcc-4= .5) > enum unfortunately IS compatible with int even in C++ (tried -Wall/-pedan= tic > etc.). I haven't checked the C++ spec. I think "int signal =3D TARGET_SIGNAL_TRAP" would be valid C++, while "enum gdb_signal signal =3D SIGTRAP" would not. I thought the latter would be the most common scenario to catch though. Maybe not. Anyway, personally, I'd just do a enum target_signal/enum gdb_signal rename, and stay with that. But, here's another idea of how to get compiler warnings/errors, that I think is more transparent to code throughout: /* An empty struct. It's the instances we care about. */ struct gdb_signal_1 { }; /* An array of all defined gdb signals. */ const struct gdb_signal_1 gdb_signals[NUM_GDB_SIGNALS]; /* gdb code uses gdb_signal, not gdb_signal_1. gdb_signal is a pointer. */ typedef struct gdb_signal_1 * gdb_signal; /* Define the constants. */ #define TARGET_SIGNAL_0 (&gdb_signals[0]) #define TARGET_SIGNAL_TRAP (&gdb_signals[5]) #define TARGET_SIGNAL_FOO (&gdb_signals[FOO]) ... Then, you can do this: gdb_signal signal =3D TARGET_SIGNAL_TRAP; and still do this: for (gdb_signal foo =3D TARGET_SIGNAL_0; sig < TARGET_SIGNAL_LAST; sig++) do_things(foo); ... all as before. But these: int sig =3D TARGET_SIGNAL_TRAP; gdb_signal sig =3D SIGTRAP; gdb_signal sig =3D TARGET_SIGNAL_TRAP; if (sig < SIGTRAP) do_things (); ... give out a warnings, fatal with -Werror. Getting at the signal integer is simply: #define GDB_SIGNAL_NUMBER(gdb_sig) \ (((gdb_sig) - TARGET_SIGNAL_0) / sizeof (gdb_sig)) All the other macros TARGET_SIGNAL_EQ|NE|GT|... disappear. Here's a compilable example: $ cat sig.c #include struct gdb_signal_1 {}; typedef struct gdb_signal_1 * gdb_signal; struct gdb_signal_1 signals[10]; #define TARGET_SIGNAL_TRAP (&signals[5]) int main () { gdb_signal sig =3D TARGET_SIGNAL_TRAP; int sig2 =3D SIGTRAP; if (sig =3D=3D sig2) { } sig =3D sig2; sig2 =3D sig; return 0; } $ gcc sig.c -o sig.o -c -Wall sig.c: In function =E2=80=98main=E2=80=99: sig.c:16: warning: comparison between pointer and integer sig.c:20: warning: assignment makes pointer from integer without a cast sig.c:21: warning: assignment makes integer from pointer without a cast --=20 Pedro Alves