Thread: If a function prototype parameter field is left empty does it assume an int?

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by brewbuck View Post
    Well, that makes sense, since you obviously have to be able to specify the actual arguments when defining the function.

    But why does it change the type promotion rules so that the call with a char is not valid? Weird.
    Because you're running the type promotion rules backwards, I think. Seeing () means the compiler will run the usual type promotions, as though it were a ,... type function--integral types get promoted to int, floating point types to double. Now that's that done, you can't go backwards and say "hey that's a char" -- there's no demotion back to a char from an int.

  2. #17
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by tabstop View Post
    Because you're running the type promotion rules backwards, I think. Seeing () means the compiler will run the usual type promotions, as though it were a ,... type function--integral types get promoted to int, floating point types to double. Now that's that done, you can't go backwards and say "hey that's a char" -- there's no demotion back to a char from an int.
    But I thought that char was promoted to int for argument passing, then converted back to char after invoking the function.

    Maybe that's not specified and I'm just thinking of in-the-field behavior.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by brewbuck View Post
    But I thought that char was promoted to int for argument passing, then converted back to char after invoking the function.

    Maybe that's not specified and I'm just thinking of in-the-field behavior.
    That might be the in-the-field behavior, but the compiler has to act as though:
    If the expression that denotes the called function has a type that does include a prototype,
    the arguments are implicitly converted, as if by assignment, to the types of the
    corresponding parameters, taking the type of each parameter to be the unqualified version
    of its declared type. The ellipsis notation in a function prototype declarator causes
    argument type conversion to stop after the last declared parameter. The default argument
    promotions are performed on trailing arguments.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM