Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!ames!ucbcad!ucbvax!dewey.soe.berkeley.edu!oster From: oster@dewey.soe.berkeley.edu (David Phillip Oster) Newsgroups: comp.lang.c Subject: Re: Enum vs Define Message-ID: <19913@ucbvax.BERKELEY.EDU> Date: Thu, 30-Jul-87 18:51:29 EDT Article-I.D.: ucbvax.19913 Posted: Thu Jul 30 18:51:29 1987 Date-Received: Sat, 1-Aug-87 11:03:35 EDT Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster) Organization: School of Education, UC-Berkeley Lines: 48 I missed the beginning of this discussion, so apologies in advance if this posting just repeats issues that have already been covered. One hard won bit of knowledge for me is how the difference between enums and defines can screw you up: in : enum { ERRMSGA = 1, ERRMSGB = 2 }; ERRMSGA is defined to be a subtype of the smallest type that will hold any of these enums. Since none of these enums are very large, you'd expect: sizeof ERRMSGA == sizeof(char) /* the parens are not necessary on the /* left hand side, but they are on the right */ On the other hand, if I had said: #define ERRMSGA 1 #define ERRMSGB 2 I would expect sizeof ERRMESGA == sizeof(int) Ordinarily, this fine distinction is harmless. However, the LightSpeed C compiler for the macintosh has been augmented with a non-standard keyword: "pascal". If you declare a function to be of type pascal, the compiler compiles a different code preamble and postable for the routine, and things that call the "pascal" routine pass their arguments to it in a different manner. In particular, the automatic conversion of char parameters into int parameters gets suppressed. (I mean, the normal process by which the caller passes a char, the callee recieves a char, but an int is really being passed on the stack.) In addition, LightSpeed C acts as if the operating system calls (which are all of type "pascal") automatically had function prototypes, i.e. it automatically coerces char to int on operating system calls. Since operating system calls, and ordinary C calls are handled correctly, the above oddity will only bite you unless you define a "pascal" routine of your own. --- David Phillip Oster --My Good News: "I'm a perfectionist." Arpa: oster@dewey.soe.berkeley.edu --My Bad News: "I don't charge by the hour." Uucp: {seismo,decvax,...}!ucbvax!oster%dewey.soe.berkeley.edu