What are the major differences between ANSI C and K&R C?

后端 未结 11 1421
不知归路
不知归路 2020-11-29 04:10

The Wikipedia article on ANSI C says:

One of the aims of the ANSI C standardization process was to produce a superset of K&R C (the first publishe

相关标签:
11条回答
  • 2020-11-29 04:33

    There are some minor differences, but I think later editions of K&R are for ANSI C, so there's no real difference anymore.
    "C Classic" for lack of a better terms had a slightly different way of defining functions, i.e.

    int f( p, q, r )  
    int p, float q, double r;  
    {  
        // Code goes here  
    }
    

    I believe the other difference was function prototypes. Prototypes didn't have to - in fact they couldn't - take a list of arguments or types. In ANSI C they do.

    0 讨论(0)
  • 2020-11-29 04:33

    Despite all the claims to the contary K&R was and is quite capable of providing any sort of stuff from low down close to the hardware on up. The problem now is to find a compiler (preferably free) that can give a clean compile on a couple of millions of lines of K&R C without out having to mess with it.And running on something like a AMD multi core processor.

    As far as I can see, having looked at the source of the GCC 4.x.x series there is no simple hack to reactivate the -traditional and -cpp-traditional lag functionality to their previous working state without without more effor than I am prepered to put in. And simpler to build a K&R pre-ansi compiler from scratch.

    0 讨论(0)
  • 2020-11-29 04:35

    The difference is:

    1. Prototype
    2. wide character support and internationalisation
    3. Support for const and volatile keywords
    4. permit function pointers to be used as dereferencing
    0 讨论(0)
  • 2020-11-29 04:36

    Function prototypes were the most obvious change between K&R C and C89, but there were plenty of others. A lot of important work went into standardizing the C library, too. Even though the standard C library was a codification of existing practice, it codified multiple existing practices, which made it more difficult. P.J. Plauger's book, The Standard C Library, is a great reference, and also tells some of the behind-the-scenes details of why the library ended up the way it did.

    The ANSI/ISO standard C is very similar to K&R C in most ways. It was intended that most existing C code should build on ANSI compilers without many changes. Crucially, though, in the pre-standard era, the semantics of the language were open to interpretation by each compiler vendor. ANSI C brought in a common description of language semantics which put all the compilers on an equal footing. It's easy to take this for granted now, some 20 years later, but this was a significant achievement.

    For the most part, if you don't have a pre-standard C codebase to maintain, you should be glad you don't have to worry about it. If you do--or worse yet, if you're trying to bring an old program up to more modern standards--then you have my sympathies.

    0 讨论(0)
  • 2020-11-29 04:41

    The biggest single difference, I think, is function prototyping and the syntax for describing the types of function arguments.

    0 讨论(0)
提交回复
热议问题