Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!usc!apple!fox!portal!cup.portal.com!Sullivan From: Sullivan@cup.portal.com (sullivan - segall) Newsgroups: comp.sys.amiga Subject: Re: #pragma PREPROCESSOR control is evil! Message-ID: <25206@cup.portal.com> Date: 20 Dec 89 03:19:17 GMT References: <10415@etana.tut.fi> <9532@microsoft.UUCP> <411@enuxha.eas.asu.edu> <6@microsoft.UUCP> Distribution: na Organization: The Portal System (TM) Lines: 171 >In article <411@enuxha.eas.asu.edu> martin@enuxha.eas.asu.edu (Ross D. Martin) wri t >es: >>In article <9532@microsoft.UUCP>, w-edwinh@microsoft.UUCP (Edwin Hoogerbeets) wri t >es: >>> # 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 > >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. [eeek!] IMHO, though, this method is a bit of a >kludge. Yes #pragma is a bit of a kludge! :) > > >#if !(defined(AMIGA) && defined(LATTICE)) > #define __chip >#endif or: #ifndef __chip #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 create some amiga code that requires placement in the chip memory, I want my compiler to tell me that something has changed when I move to a new environment. I *will* need to think about the way I'm planning on implementing this thing on any other architecture, and I would just as soon have the compiler remind me to do so. By comparison, #if, #define, #endif is much less ugly than losing my __chip references. >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 or: #ifndef __chip #define __chip #endif #define CHIP __chip but really I would probably use: #ifdef AMIGA typedef __chip char *rastport[ MAXWIDTH * MAXHEIGHT * PLANES / 8 ]; #else ... #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. > I've never met anyone who really thinks that C code can be ported without any changes. Especially C code which is machine-specific. I can't imagine using an Amiga rastport on any other machine,... nor for that matter can I imagine any set of architectures which by their nature allow structures to be defined such that machine dependant features will work with each of them. Similarity between machines is really meaningless until you get to a higher level of control. And at that level, the subroutines which implement the windows, mouse requests, or what have you, can allocate memory however they please, without ANY reference to CHIP, __chip, or #pragma in the high level routines calling them. >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. > I disagree. Register, static, automatic, and even __chip are all code generation details. Register means allocate a machine register if one is available. Static means allocate main memory. Automatic means allocate stack space. __chip means allocate Amiga specific chip memory. (#pragma is a PREPROCESSOR instruction fer gosh sake.) >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 good use of pragmas. > - enabling and disabling generation of stack-checking code good use of pragmas. > - enabling and disabling generation of intrinsic functions good use of pragmas. > >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." ....so your point is that even MicroSoft knows that specialized keywords should be used for storage size, and placement definitions. (ie: for types, which is exactly what pragmas shouldn't be used for (well using a pragma to define the primary memory model, or the size of an int isn't evil, but declaring a variable using a pragma IS.) > >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 ...]) > eeeeek! no. Don't do this. Please! >> >> Ross Martin > >stephan("You can tune a piano, but you can't armadillo"); #pragma dreammode ON .... hey how about #pragma programming language. All source files should end in "p.rag". If you can't interpret the meaning of any line of code, just ignore it. Demo code is listed below: #pragma I want to play a game. You be the bad guys and I'll be the #pragma good guys. Oh, and make it nice and graphical too. Thanks. As you can see by the code above, the language is very terse. This two line program is equivalent to about 50,000 lines of C, and in fact generates code equivalent to NetHack (with a few enhancements naturally.) Or alternatively it compiles to nothing at all depending on which compiler you have... -ss #pragma dreammode OFF