home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol144 / nesting.not < prev    next >
Encoding:
Text File  |  1985-02-10  |  2.1 KB  |  92 lines

  1. NOTES ON NESTING OF PREPROCESSOR DIRECTIVES IN BDS C.
  2.  
  3.  
  4. Versions of the BDS C compiler from 1.45a+ do support
  5. nesting of the preprocessor directives.
  6.  
  7. Leor specifies that  #if <exp> compiler directive is
  8. supported with restrictions on <exp>, and that nesting of
  9. conditional compile directives is permitted with the
  10. limitation that #else directives must be followed by a
  11. matching #endif.  This last point is a little unclear to me
  12. but 'SEEMS' to say that
  13.  
  14. #ifdef    A
  15.  
  16. #ifdef    B
  17. #else    /*B*/
  18. #endif    /*B*/
  19. #endif    /*A*/
  20.  
  21.     is permitted, but
  22.  
  23. #ifdef    A
  24.  
  25. #else    /*A*/
  26. #ifdef    B
  27. #endif    /*B*/
  28. #endif    /*A*/
  29.  
  30.     is not.???
  31.  
  32.     He also states that the preprocessor does now generate a
  33. valid error, rather that wandering off through source.
  34.  
  35.     Also parameterized #defines are supported as per K & R.
  36.  
  37.     K & R page 207pp indicates that both forms of the #if...
  38. nesting above should be legal.    He implies that a
  39. conditional compile directive (#if...) MUST be followed by
  40. an #endif, but may have an optional #else before the #endif.
  41. Where nesting is permitted (no restrictions) and #else's act
  42. upon the most recently active #if..., #endif's act upon the
  43. most recently active #if... or #else.
  44.  
  45. i.e.
  46.  
  47. #if...    A
  48. .
  49. .
  50. #if...    B
  51. .
  52. .
  53. #else    /*B*/
  54. .
  55. #if...    C
  56. .
  57. .
  58. #else    /*C*/
  59. .
  60. .
  61. #endif    /*C*/
  62. .
  63. .
  64. #endif    /*B*/
  65. .
  66. .
  67. #endif    /*A*/
  68. รจ
  69.  
  70.         is o.k.
  71.  
  72.  
  73.     On testing of the compiler with (granted) a fairly
  74. simple test for compiler nesting, the BDS C compiler 1.46 seems
  75. to behave exactly as K & R describes, and as I would expect
  76. it to.    When I tried to upset it, it upset me with 'Not in a
  77. conditional block', or EOF when expecting #endif etc error
  78. messages.  #defines that exist in an unenabled block of code
  79. do not get seen at all, so nesting of #defines inside
  80. #if...'s works as expected as well.
  81.  
  82.  
  83.     If you know of any examples of nesting that do not work
  84. in 1.46, or know any other (possibly clearer) descriptions
  85. on the operation and nesting of these directives in C please
  86. let me know.
  87.  
  88.     Hope this helps clear up a little of the confusion.
  89.  
  90.  
  91.             John Woolner.
  92.