Hacker News new | past | comments | ask | show | jobs | submit login

>pretty sure K&R C is a subset of ANSI C,

Not so, AFAICT. For one thing, K&R function declarations looked like this:

  int main(argc, argv)
  int argc, char **argv
  {
  ...
  }
Ever wonder where 1TBS came from?

Also, in K&R, function prototypes didn't list args.




Yes, function declarations did look like that. And GCC accepts it totally silently in pedantic ANSI C mode, not even warnings:

    11:44:57 cory@tizona /home/cory/Workspace/test
    $ cat knr.c
    #include <stdio.h>
    
    main(argc, argv)
            int argc;
            char **argv;
    {
            int z = foo(3, 4);
            printf("foo is %d\n", z);
    }
    
    foo(x, y)
    {
            return x + y;
    }
    
    
    11:44:59 cory@tizona /home/cory/Workspace/test
    $ gcc -std=c89 -pedantic -o knr knr.c
    
    11:45:07 cory@tizona /home/cory/Workspace/test
    $ ./knr
    foo is 7
    
    11:45:11 cory@tizona /home/cory/Workspace/test
    $ gcc -v
    Reading specs from /usr/lib64/gcc/x86_64-slackware-linux/5.3.0/specs
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-slackware-linux/5.3.0/lto-wrapper
    Target: x86_64-slackware-linux
    Configured with: ../gcc-5.3.0/configure [...]
    Thread model: posix
    gcc version 5.3.0 (GCC) 
I seem to recall the compatibility was deliberate on the part of the ANSI C WG, for hopefully obvious reasons.


Huh. Didn't know that. Okay...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: