Thread: Declare 'int main()', in C, isn't the same as in C++

  1. #16
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    So... it is an obsolescent feature... so what? It is a feature still present in both standards and maybe will be removed... It makes this statement just a minor warning, not a rule!

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I'm using that to illustrate why this is not a function prototype:
    Code:
    int f();
    That it is an obsolescent feature is secondary to my point, and I note that you brought up the point that it is an obsolescent feature yourself in post #3, not me. (I merely used it so I didn't have to go digging around the standard for other examples.)
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Ok, what we have until now: This declarator uses an obsolete syntax (but valid); You said this is not a prototype, it is (unless we discard obsolete, but possible, constructions)... I said we can do calls to functions with empty parameter list with any number and types of arguments. The standard advises against this pratice (I granted you this)... And the list of undefined behavior (Annex J) only says about functions without prototypes in scope...

    Take a look at this advice @ 6.5.2.2 $2 and you'll see: "If the expression that denotes the called function has a type that includes a prototype, the number of arguments shall agree with the number of parameters...". Notice the use of "shall"... The entire specification is an adivice, too little is prohibited... I stated the fact, as far as I know, that every C compiler accepts this behavior without any warnings or errors.

    If we agree that "shall" should be interpreted as "mandatory", then, every compiler I know is wrong (from the old Turbo-C 2.01 to the latest GCC, including old proprietary compilers for AIX, HP-UX, VMS - yep, I got my hands on them in the past!)...
    Last edited by flp1969; 03-21-2019 at 06:27 PM.

  4. #19
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Again... I agree this is stupid implementation. I don't like to use empty parameters list on a prototype or function definition...

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by flp1969
    You said this is not a prototype, it is (unless we discard obsolete, but possible, constructions).
    It isn't. The standard says it isn't because it doesn't conform to what makes a function declaration a prototype: by definition, it provides no information on the number and types of the parameters, yet that is what makes a function declaration a prototype. Your interpretation of the standard is in error because of this misunderstanding.

    Compilers aren't in violation if they take no action for undefined behaviour (i.e., it is the code that is standard non-conforming), and in this case compilers cannot even take action to emit a warning when relevant parts of the program are compiled separately.

    Yes, we definitely agree on the most practically important point. Personally, I don't see people using this much any more, unless they are old-timers who know what they are doing, or newcomers especially from C++ who don't. We don't have to worry about the former, and the latter can easily be informed, like you did in this thread.
    Last edited by laserlight; 03-21-2019 at 07:34 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-11-2015, 05:20 AM
  2. Replies: 6
    Last Post: 05-08-2014, 10:57 AM
  3. (split) yet another how to declare main thread
    By DevoAjit in forum C Programming
    Replies: 1
    Last Post: 10-28-2011, 05:54 AM
  4. How to declare a global variable in Main()
    By vnrabbit in forum C Programming
    Replies: 2
    Last Post: 06-20-2002, 12:59 PM
  5. void main(), int main(), argc, argv[]????
    By Jonny M in forum C Programming
    Replies: 3
    Last Post: 03-06-2002, 09:12 AM

Tags for this Thread