[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#202319: marked as done (cpp: enum in #if does not cause warning/error)

Your message dated 21 Jul 2003 23:06:05 +0200
with message-id <87k7abpp36.fsf@student.uni-tuebingen.de>
and subject line Bug#202319: cpp: enum in #if does not cause warning/error
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

Received: (at submit) by bugs.debian.org; 21 Jul 2003 18:52:09 +0000
>From bernt@gollum.norang.ca Mon Jul 21 13:44:05 2003
Return-path: <bernt@gollum.norang.ca>
Received: from cpe000102d0fe24-cm0f1119830776.cpe.net.cable.rogers.com (thorin.norang.ca) [] 
	by master.debian.org with esmtp (Exim 3.35 1 (Debian))
	id 19efdl-0005gd-00; Mon, 21 Jul 2003 13:44:05 -0500
Received: from gollum.norang.ca (root@gollum.norang.ca [])
	by thorin.norang.ca (8.12.9/8.12.9/Debian-4) with ESMTP id h6LIhxsJ005737;
	Mon, 21 Jul 2003 14:44:00 -0400
Received: from gollum.norang.ca (bernt@localhost [])
	by gollum.norang.ca (8.12.9/8.12.9/Debian-5) with ESMTP id h6LIhxMT030213;
	Mon, 21 Jul 2003 14:43:59 -0400
Received: (from bernt@localhost)
	by gollum.norang.ca (8.12.9/8.12.9/Debian-5) id h6LIhxgw030211;
	Mon, 21 Jul 2003 14:43:59 -0400
Message-Id: <[🔎] 200307211843.h6LIhxgw030211@gollum.norang.ca>
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="ISO-8859-1"
From: Bernt Hansen <bernt@norang.ca>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: cpp: enum in #if does not cause warning/error
X-Mailer: reportbug 2.19
Date: Mon, 21 Jul 2003 14:43:58 -0400
Delivered-To: submit@bugs.debian.org
X-Spam-Status: No, hits=-6.0 required=4.0
X-Spam-Checker-Version: SpamAssassin 2.53-bugs.debian.org_2003_07_20 (

Package: cpp
Version: 3:3.3-2
Severity: normal
Tags: upstream

If an enumerated type is used in #if statements no warning/error is given and
the TRUE branch of the #if is always executed.

Using enum in #if is declared illegal by K&R along with cast and sizeof
(page 91, paragraph 2 of 4.11.3 of "The C Programming Language, Second
Edition" [ANSI C]).

We use enum and #defines fairly interchangeably in header files for
project constants and ran into a case where I want to conditionally compile 
code based on the value of the constant -- which happened to be an enumerated

If the constant is a #define it works great.  If the constant is an enum
value it always evaluates the TRUE case of the
    #if ... 
which is not obvious when reading the code.

---- sample code follows ----

#include <stdio.h>

enum {S=32, T=33};
#define MY T

int main(void)
#if (MY == S)
    printf("MY(%d) == S\n", MY);
    printf("MY(%d) != S\n", MY);
    return 0;

---- end of sample code ----

If the enum {S=32, T=33}; is replaced with
#define S 32
#define T 33
the code compiles properly.

Since normally the constants/enums are lost in some project
header file you won't necessarily know if it was created by 
an enum or a #define and some warning or error message would be

Many thanks for an awesome compiler guys!


-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux gollum 2.4.21-k7 #1 Wed Jul 2 13:30:26 EDT 2003 i686
Locale: LANG=en_CA, LC_CTYPE=en_CA

Versions of packages cpp depends on:
ii  cpp-3.3                    1:3.3.1-0pre0 The GNU C preprocessor

-- no debconf information

Received: (at 202319-done) by bugs.debian.org; 21 Jul 2003 21:06:27 +0000
>From falk.hueffner@student.uni-tuebingen.de Mon Jul 21 16:06:08 2003
Return-path: <falk.hueffner@student.uni-tuebingen.de>
Received: from mx01.uni-tuebingen.de [] 
	by master.debian.org with esmtp (Exim 3.35 1 (Debian))
	id 19ehrE-0008TW-00; Mon, 21 Jul 2003 16:06:08 -0500
Received: from juist (semeai.Informatik.Uni-Tuebingen.De [])
	by mx01.uni-tuebingen.de (8.12.3/8.12.3) with ESMTP id h6LL65Su013789
	for <202319-done@bugs.debian.org>; Mon, 21 Jul 2003 23:06:06 +0200
Received: from falk by juist with local (Exim 3.36 #1 (Debian))
	id 19ehrB-00009a-00
	for <202319-done@bugs.debian.org>; Mon, 21 Jul 2003 23:06:05 +0200
X-Face: "iUeUu$b*W_"w?tV83Y3*r:`rh&dRv}$YnZ3,LVeCZSYVuf[Gpo*5%_=/\_!gc_,SS}[~xZ
To: 202319-done@bugs.debian.org
Subject: Re: Bug#202319: cpp: enum in #if does not cause warning/error
References: <[🔎] 200307211843.h6LIhxgw030211@gollum.norang.ca>
From: Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
Date: 21 Jul 2003 23:06:05 +0200
In-Reply-To: <[🔎] 200307211843.h6LIhxgw030211@gollum.norang.ca>
Message-ID: <87k7abpp36.fsf@student.uni-tuebingen.de>
Lines: 6
User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.5 (cabbage)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-AntiVirus: checked by AntiVir Milter 1.0.2; AVE; VDF
Delivered-To: 202319-done@bugs.debian.org
X-Spam-Status: No, hits=-3.3 required=4.0
X-Spam-Checker-Version: SpamAssassin 2.53-bugs.debian.org_2003_07_20 (

Use -Wundef to warn about use of undefined identifiers in #if. The
preprocessor has no way of knowing whether an undefined identifier is
an enumeration constant, so you'll get warnings about all of them.


Reply to: