gcc doesn't warn about calling a nullary function WITH parameters?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Harry2o
    New Member
    • Oct 2009
    • 6

    #1

    gcc doesn't warn about calling a nullary function WITH parameters?

    Can anyone tell me, why in the blazes GCC (e.g. 4.4.3) does not warn about or error the incorrect call of a nullary function?

    Code:
    void hello() {
    }
    
    int main( int argc, char* argv[] ) {
     int test = 1234;
     hello(test);
     
     return 0;
    }

    -----
    Update:
    also see http://stackoverflow.com/questions/3...ith-parameters
    Last edited by Harry2o; Aug 10 '10, 01:25 PM. Reason: trackback link to slashdot with same question
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    3.4.4 errors out with 'too many argument' as expected. Does your gcc {emit code that} actually calls it? What if you call function with 1 argument without argumnents?

    Comment

    • Harry2o
      New Member
      • Oct 2009
      • 6

      #3
      void hello() {} and calling hello( test ) goes without error
      void hello() {} and calling hello( test, test2 ) goes without error

      void hello( int c ) {} and calling hello( ) goes with error "too few arguments" (as expected)

      void hello( int c ) {} and calling hello( test, test2 ) goes with error "too many arguments" (as expected)

      It seems a nullary function is a special case and GCC doesn't warn or error .....

      Comment

      • newb16
        Contributor
        • Jul 2008
        • 687

        #4
        In C ( not C++ ) it's true and empty argument list means any number of arguments.

        Comment

        • Harry2o
          New Member
          • Oct 2009
          • 6

          #5
          newb16, thank you.

          Two questions:
          - if an empty argument list means any number of arguments, how are you supposed to access them? Directly on the stack? Are you actually supposed to access them?
          - do you have any reference that this behavior is according to the standard?

          Comment

          • newb16
            Contributor
            • Jul 2008
            • 687

            #6
            From wiki - "This provides backward compatibility with K&R C, which lacked prototypes."
            So there may be no way to use this 'feature' in standard C.

            Comment

            • donbock
              Recognized Expert Top Contributor
              • Mar 2008
              • 2427

              #7
              You are inadvertently using an "old-style" function definition for hello.

              Do this and you will get a compiler warning on line 6:
              Code:
              void hello(void) {
              }

              Comment

              Working...