home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Journal 1990 - 1995 / CUJ.iso / mac / 1991.txt < prev    next >
Text File  |  1996-02-07  |  3MB  |  99,905 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613. Resources For Portable C Applications
  614.  
  615.  
  616. Thomas Plum
  617.  
  618.  
  619. Dr. Thomas Plum is President of Plum Hall Inc., a training firm that also
  620. supplies the leading ANSI C validation suite. Dr. Plum serves as Vice Chair of
  621. ANSI X3J11, the committee that developed the C standard.
  622.  
  623.  
  624. Let me begin with a bald assertion. Bald Assertion #1: As of 1991, a C source
  625. file should be either (a) written in non-portable ANSI/ISO Standard C for a
  626. specific environment (e.g. a device driver), or (b) written in strictly
  627. portable Standard C suitable for compilation and execution in any environment
  628. whatsoever. There is no justification for intermediate levels of "somewhat
  629. portable" code.
  630. This wasn't what I set out to write about, but it is the inescapable
  631. conclusion given current resources and projects. In this article, I will
  632. describe some of the resources that are likely to be important for your work
  633. on portable C projects. Contact address information is available at the end of
  634. the article.
  635.  
  636.  
  637. Books On Portability
  638.  
  639.  
  640. There are two comprehensive survey books on the line-by-line portability
  641. coding issues: Portable C, by Rabinowitz and Schaap, and Portability and the C
  642. Language, by Jaeschke. (See Resources at the end of this article.) Rabinowitz
  643. and Schaap's book traces its origins back to a seminar that Schaap and I wrote
  644. for Bell Labs in 1980. At the time Schaap was the first consultant for the
  645. fledgling Plum Hall Inc. The work has grown into a wealth of detail. It is
  646. very accurate information. The Jaeschke book is also extremely authoritative.
  647. A project leader responsible for portability should probably read both books.
  648. Nevertheless, both books have a point of view that I quarrel with. Besides the
  649. current C Standard, they cover multiple flavors of "old C" in great detail.
  650. These dozens (or hundreds?) of pages on "old C problems" are in themselves a
  651. convincing reason to stick to strict Standard C. The world could use a
  652. "Standard-only" version of each book. Aside from this, both books are a
  653. valuable condensation of practical advice from years of project experience.
  654. Also in the category of collected hints from prior experience is Plum Hall's
  655. own book, C Programming Guidelines, ("CPG," now in Second Edition for Standard
  656. C). Presented in the form of a project coding standard, CPG contains
  657. suggestions on data types, operators, and library functions for portable
  658. coding. CPG is available in an inexpensive machine-readable format to serve as
  659. the starting point for each project's own coding standard.
  660. The fundamental portability resource is, of course, the ANSI C Standard
  661. itself. It represents seven years of work by hundreds of C experts. The
  662. corresponding ISO Standard is expected to be official by the end of 1990,
  663. identical in every way but typographic layout.
  664.  
  665.  
  666. Portability Testing Software
  667.  
  668.  
  669. Another condensation of practical experience is the FlexeLint tool from Gimpel
  670. Software. This is a compile-time syntax analyzer that monitors adherence both
  671. to Standard C and to a large collection of portability-enhancing coding
  672. restrictions. For years, Gimpel has had an active customer base suggesting
  673. (and demanding) practical compile-time tests for portability. FlexeLint
  674. scrutinizes for portability problems involving the signedness of char,
  675. variations in character sets, sizes of integers, pointer casts, declarations
  676. and linkage, called-function vs. calling-function discrepancies, etc.
  677. I am especially fond of FlexeLint's ability to selectively disable specific
  678. tests. When it comes to heuristic coding rules, no two projects agree
  679. completely. I've used FlexeLint on several Plum Hall projects, and it works
  680. well.
  681. Similar capabilities are described for the C Portability Verifier from
  682. Mindcraft, but I haven't been able to test it yet.
  683. Because the ANSI C Standard is the only official Standard for C, I suggest
  684. another bald assertion. Bald Assertion #2: Any organization that cares about
  685. portable C will insist that its procurements require certified
  686. Standard-conforming compilers.
  687. Vendors who want to sell compilers to your project can obtain this
  688. certification from the European Compiler Testing Service (ECTS). This body
  689. includes the British Standards Institution (UK), AFNOR (France), and IMQ
  690. (Italy). (The US government standards agency, NIST, plans a different
  691. approach, probably available late 1991 or early 1992. More on this in another
  692. article.) ECTS uses the Plum Hall Validation Suite for C as its criterion for
  693. certification.
  694. I'll stake my professional reputation on this claim: If your compiler vendor
  695. truthfully claims to conform to the C Standard, then that vendor's product can
  696. pass the Plum Hall Suite and get officially certified. You do not have to rely
  697. upon advertising claims in your procurements. If customers insist upon
  698. Standard-conforming compilers, vendors will provide them. Several vendors
  699. already have been fully certified by ECTS. There are dozens of others who
  700. could get certified if customers demanded it.
  701. The Standard is central to the subject of C portability because it is the
  702. "treaty" between compiler vendors and programming projects. It defines exactly
  703. what capabilities the portable C program can expect from every environment.
  704.  
  705.  
  706. A Model Implementation
  707.  
  708.  
  709. The strictness of this treaty makes possible a new form of portability-testing
  710. tool. It is one that enforces every detailed requirement that the Standard
  711. imposes upon an application program. Such a tool is the C Model
  712. Implementation, commissioned and distributed by the British Standards
  713. Institution and produced by Knowledge Software Ltd.
  714. Basically, the C Model is an extremely fussy C implementation that
  715. syntax-checks your application for every compile-time requirement of the
  716. Standard. It also generates a form of intermediate p-code, runs the p-code
  717. through an equally fussy linker, then executes the program with diagnosis of
  718. every runtime "undefined behavior." The net result is that, if your program
  719. compiles and runs clean under the C Model, and you then compile and run it on
  720. an environment that conforms faithfully to the Standard, the program will
  721. compile and run clean there, too.
  722. Thus, the C Model is an interesting departure from the item-by-item
  723. accumulation of heuristics that characterized the previous resources
  724. (including my own C Programming Guidelines). It was produced, test-by-test,
  725. directly from the Standard itself.
  726. During this past year, the C Model has found more subtle non-portabilities in
  727. our Plum Hall Suite than did all the specific hardware environments. It
  728. demonstrates to its users that strictly portable C takes some discipline to
  729. produce, but also that it can be done.
  730.  
  731.  
  732. Shrink-Wrapped C
  733.  
  734.  
  735. Closely related in concept to the C Model is the Architecture-Neutral
  736. Distribution Format (ANDF) project of the Open Software Foundation (OSF). The
  737. goal here is to distribute "shrink-wrapped" applications that can be run
  738. without modification on any suitable target system. One industry standard
  739. assumed by ANDF is ANSI/ISO Standard C (as verified by the Plum Hall Suite).
  740. Another is the OSF/1 version of the UNIX operating system, which in turn is
  741. specified to meet the IEEE 1003 (POSIX) standard and the X/Open UNIX
  742. portability standard. OSF is currently conducting a competition (now down to
  743. four finalists) for a technology that will allow applications to be
  744. distributed in a "semi-compiled" form. Actual machine-specific code generation
  745. is postponed until the end-user performs the "install" process.
  746. Obviously, an application intended for shrink-wrap distribution must be
  747. totally free from dependencies upon the specific target architectu