Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mcvax!ukc!eagle!icdoc!cam-cl!am From: am@cl.cam.ac.uk (Alan Mycroft) Newsgroups: comp.lang.c Subject: Re: Enum vs Define Message-ID: <729@jenny.cl.cam.ac.uk> Date: Tue, 30-Jun-87 09:13:39 EDT Article-I.D.: jenny.729 Posted: Tue Jun 30 09:13:39 1987 Date-Received: Sun, 12-Jul-87 09:24:10 EDT References: <196@dbase.UUCP> Reply-To: am@cl.cam.ac.uk (Alan Mycroft) Organization: U of Cambridge Comp Lab, UK Lines: 25 Keywords: enum, define In article <196@dbase.UUCP> awd@dbase.UUCP (Alastair Dallas) writes: > (what is the difference between) > enum { > ERRMSGA = 1, > ERRMSGB = 2 > }; >and > > #define ERRMSGA 1 > #define ERRMSGB 2 > Here's one which is facetious, but none-the-less risky if you haven't thought carefully: If I say if (ERRMSGA == ERRMSGB) ... then ... is always executed in both cases. Now, if I do #if (ERRMSGA == ERRMSGB) ... #endif then the ANSI-C draft REQUIRES(!!!!!) the first case NOT to compile ... and the second case to compile ... . Put simply, all undefined macros (including enum constants) are treated as 0 by the pre-processor, often (sadly) without warning.