home *** CD-ROM | disk | FTP | other *** search
- //
- // SELECT.h -- useful macros
- // Written and copyright 1994 by Raf Schietekat.
- // Version 1.0. All rights reserved.
- // This notice may not be removed from this source code.
- //
- // This code is included in the MiscKit by permission from the author
- // and its use is governed by the MiscKit license, found in the file
- // "LICENSE.rtf" in the MiscKit distribution. Please refer to that file
- // for a list of all applicable permissions and restrictions.
- //
-
- // These macros do not use the "MISC" prefix because that would ruin
- // their elegance. If they cause you grief, just #define MISC_SKIP_SELECT
- // before importing the MiscBase.h or misckit.h...
-
- /*
- Changes should be sent to Raf Schietekat, the author.
- This file may only be used in unchanged form.
- */
- /* a multi-clause selector */
- #define SELECT if(0){
- #define INTERMEZZO(d) }else if((d),0){
- #define IF(d) }else if(d){
- #define IFNOT(d) }else if(!(d)){
- #define IFDEFAULT }else{
- #define ENDSELECT }
- /* contrived example:
- SELECT -- this is always used to start the construct
- -- don't put anything here: it will not be executed!
- IF(a==b) -- the prototypical case: if the condition is true
- -- the block is executed and the construct is exited, otherwise
- -- the next clause is tested
- --var-- int c; -- you can declare local variables as in any {} block
- c=a+b; printf("a=b=%i\n",c);
- INTERMEZZO(printf("a=%i, b=%i\n",a,b))
- -- will unconditionally execute and always proceed to the next test
- INTERMEZZO(printf("compound statements should be broken up like this\n"))
- -- the INTERMEZZO ``body'' will never be executed,
- -- and will normally be empty
- IFNOT(a<b) SELECT
- IF(b==0)
- printf("b==0\n");
- IFDEFAULT -- just to show appropriate nesting
- ENDSELECT
- IFDEFAULT
- printf("IFDEFAULT and its block are of course optional\n");
- ENDSELECT -- always end the construct with this ``keyword''
- */
-
- /*overriding fall-through as the default in a switch statement*/
- #define CASE break;case
- #define DEFAULT break;default
- /* contrived example:
- switch(n){
- case 0: printf("always use case, not CASE, for the first one\n");
- -- to avoid a spurious warning by the overzealous compiler
- CASE 1: printf("isn't the absence of ``break'' a liberation?\n");
- DEFAULT: printf("and that's the last one\n");
- }
- */
-