main() in C90/C95

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ioannis Vranos

    main() in C90/C95

    Well we all know K&R2 uses main() and not int main(). Also in K&R2, in
    chapter 4.1, there is a definition of a function:

    dummy() {}

    and it is stated that if the returned type is omitted, int is used.


    So I suppose in C90/C95

    main() is equivalent to int main() right?


    That is, the same stuff with C90/95 int variables where,

    x= 7;

    means int x= 7;
  • santosh

    #2
    Re: main() in C90/C95

    Ioannis Vranos wrote:
    Well we all know K&R2 uses main() and not int main(). Also in K&R2, in
    chapter 4.1, there is a definition of a function:
    >
    dummy() {}
    >
    and it is stated that if the returned type is omitted, int is used.
    >
    >
    So I suppose in C90/C95
    >
    main() is equivalent to int main() right?
    Yes. This (implicit int return) was removed from C99.
    That is, the same stuff with C90/95 int variables where,
    >
    x= 7;
    >
    means int x= 7;

    Comment

    • =?UTF-8?q?Harald_van_D=C4=B3k?=

      #3
      Re: main() in C90/C95

      On Sat, 01 Mar 2008 13:36:48 -0800, Keith Thompson wrote:
      Harald van Dijk <truedfx@gmail. comwrites:
      >On Sat, 01 Mar 2008 12:18:16 -0800, Keith Thompson wrote:
      >>I think that pre-ANSI C was more forgiving of declarations with
      >>missing types. It was probably the ambiguity of things like "x = 7;",
      >>or even just "x;", that led to the rules being tightened a bit.
      >>
      >Out of curiosity, do you know of any specific implementations that
      >accept that?
      [...]
      >
      I can think of a couple of old implementations that would probably
      accept it without complaint, but I don't currently have easy access to
      them.
      >
      But gcc 3.4.4 compiles and runs this, and produces the output "x = 42":
      >
      === CUT HERE ===
      x;
      >
      #include <stdio.h>
      int main(void)
      {
      x = 42;
      printf("x = %d\n", x);
      return 0;
      }
      === AND HERE ===
      Thank you. I now see it also allows 'x = 42;' (and of course, the original
      'x= 7;') at global scope, it's just at function scope that it rejects it.
      As you mentioned, a diagnostic is generated for the code, so the
      standard's requirements are met.

      Comment

      • Kenny McCormack

        #4
        Re: main() in C90/C95

        In article <9a631$47c9cedb $541dfcd3$13604 @cache2.tilbu1. nb.home.nl>,
        Harald van Dijk <truedfx@gmail. comwrote:
        ....
        >Thank you. I now see it also allows 'x = 42;' (and of course, the original
        >'x= 7;') at global scope, it's just at function scope that it rejects it.
        >As you mentioned, a diagnostic is generated for the code, so the
        >standard's requirements are met.
        And thank GOD for that.

        Comment

        Working...