Path: utzoo!attcan!uunet!microsoft!w-stephm From: w-stephm@microsoft.UUCP (Stephan Mueller) Newsgroups: comp.sys.amiga Subject: __chip keyword is evil Keywords: __chip, evil Message-ID: <6@microsoft.UUCP> Date: 18 Dec 89 19:28:31 GMT References: <10415@etana.tut.fi> <9532@microsoft.UUCP> <411@enuxha.eas.asu.edu> Reply-To: w-stephm@microsoft.UUCP (Stephan Mueller) Organization: Microsoft Corp., Redmond WA Lines: 91 In article <411@enuxha.eas.asu.edu> martin@enuxha.eas.asu.edu (Ross D. Martin) writes: >In article <9532@microsoft.UUCP>, w-edwinh@microsoft.UUCP (Edwin Hoogerbeets) writes: >> # pragma token-sequence[opt] >> >> causes the processor to perform an implementation-dependent action. An >> unrecognized pragma is ignored. >> >> Why __chip? We've got the PORTABLE mechanism already. Why not use it? >> Was there some good technical reason? (__chip must go. This is not >> negotiable. ;-) > >Yes it is. :-) > No, actually as it turns out, it is not. :-) :-) (Two smileys, upping the anty) >I don't see what you have against __chip. It is portable. Just #define >it to something harmless to do a port. I believe you can #define something >to a null string, can't you? If not, there are several do-little modifiers >out there that should work ok. Perhaps #define __chip static? >Pragmas involve more typing to get less clear, clean code. Not a good idea >in my book. You are correct that one can #define something to the NULL string, so your method will work, and would be the logical method if we didn't have something better, like #pragma. IMHO, though, this method is a bit of a kludge. I don't believe that __chip is as portable as using a #pragma. True, it isn't much work to put #define __chip at the top of a program when porting it, but it is more work than doing absolutely nothing, which is what would be required using the #pragma method. To do the #define right, would probably require something like the following. (The AMIGA and LATTICE symbols should be replaced by whatever the compiler predefines for you.) #if !(defined(AMIGA) && defined(LATTICE)) #define __chip #endif which is pretty ugly. Also, this is probably more typing than a good #pragma would be. The conditional is not needed if we are using a #pragma either, which to me means clearer, cleaner code. Getting a bit nit pickier, if I #define something, I like to stick to the fairly standard practice of having my symbols in all upper case, so I would likely use: #if defined(AMIGA) && defined(LATTICE) #define CHIP __chip #else #define CHIP #endif and then declare appropriate structures with the CHIP attribute. Now, we have a lot more typing, but at least when I port the program, no additional #defines are required. On a more philosophical level, the __chip stuff has nothing to do with any data structure or any algorithm. It is a code generation detail, and so, doesn't belong in the body of a C program which is supposed to be a high-level description of the program. As an example, consider Microsoft C 5.1 (context switch into the wonderful world of MS-DOS now) MSC features #pragmas for all kinds of code-generation related things: - enabling and disabling of various kinds of optimizations - enabling and disabling generation of stack-checking code - enabling and disabling generation of intrinsic functions Conversely, MSC uses additional keywords for some kinds of code-generation related things: - specifying Pascal or C calling convention for functions - specifying size of pointers. About these additional keywords, the MSC manual states: "The disadvantage of using these keywords is that they are specific to the MS-DOS implementation of Microsoft C and, thus, are not portable to other operating environments." Now, assuming I've convinced you we should be using #pragma, what should the syntax of such a #pragma be? Proposal : #pragma chip (identifier1 [, identifier2 ...]) > > Ross Martin stephan("You can tune a piano, but you can't armadillo");