home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / MiscKit / Headers / misckit / SELECT.h < prev   
Encoding:
C/C++ Source or Header  |  1994-03-07  |  2.4 KB  |  62 lines

  1. //
  2. //    SELECT.h -- useful macros
  3. //        Written and copyright 1994 by Raf Schietekat.
  4. //                Version 1.0.  All rights reserved.
  5. //        This notice may not be removed from this source code.
  6. //
  7. //    This code is included in the MiscKit by permission from the author
  8. //    and its use is governed by the MiscKit license, found in the file
  9. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  10. //    for a list of all applicable permissions and restrictions.
  11. //    
  12.  
  13. // These macros do not use the "MISC" prefix because that would ruin
  14. // their elegance.  If they cause you grief, just #define MISC_SKIP_SELECT
  15. // before importing the MiscBase.h or misckit.h...
  16.  
  17. /*
  18. Changes should be sent to Raf Schietekat, the author.
  19. This file may only be used in unchanged form.
  20. */
  21. /* a multi-clause selector */
  22.   #define SELECT          if(0){
  23.   #define   INTERMEZZO(d)   }else if((d),0){
  24.   #define   IF(d)           }else if(d){
  25.   #define   IFNOT(d)        }else if(!(d)){
  26.   #define   IFDEFAULT       }else{
  27.   #define   ENDSELECT       }
  28.   /* contrived example:
  29.     SELECT     -- this is always used to start the construct
  30.       -- don't put anything here: it will not be executed!
  31.       IF(a==b) -- the prototypical case: if the condition is true
  32.         -- the block is executed and the construct is exited, otherwise
  33.         -- the next clause is tested
  34.         --var-- int c; -- you can declare local variables as in any {} block
  35.         c=a+b; printf("a=b=%i\n",c);
  36.       INTERMEZZO(printf("a=%i, b=%i\n",a,b))
  37.         -- will unconditionally execute and always proceed to the next test
  38.       INTERMEZZO(printf("compound statements should be broken up like this\n"))
  39.         -- the INTERMEZZO ``body'' will never be executed,
  40.         -- and will normally be empty
  41.       IFNOT(a<b) SELECT
  42.         IF(b==0)
  43.           printf("b==0\n");
  44.         IFDEFAULT -- just to show appropriate nesting
  45.         ENDSELECT
  46.       IFDEFAULT
  47.         printf("IFDEFAULT and its block are of course optional\n");
  48.       ENDSELECT -- always end the construct with this ``keyword''
  49.     */
  50.  
  51. /*overriding fall-through as the default in a switch statement*/
  52.   #define CASE      break;case
  53.   #define DEFAULT   break;default
  54.   /* contrived example:
  55.     switch(n){
  56.       case 0: printf("always use case, not CASE, for the first one\n");
  57.         -- to avoid a spurious warning by the overzealous compiler
  58.       CASE 1: printf("isn't the absence of ``break'' a liberation?\n");
  59.       DEFAULT: printf("and that's the last one\n");
  60.       }
  61.     */
  62.