Ever look at old code and think? What the hell was I smoking?

Pages: 12345
NoXzema wrote:
Where does it say this? That's not how the standard works.. you cannot just declare rules to suit your own argument. It never says that these are the only valid forms of main.

EDIT: It does say that main may have either no parameters or two parameters if that's what you mean. It doesn't even mention the type of those two parameters and thus, any type can be used. Of course, doing so isn't reliable. http://ideone.com/J2bUu9
So you think that something has to be written in plain English words for it to be part of the standard? We might as well abandon the C and C++ standards entirely at this point and just wing it with what we think you will agree with.
Last edited on
"What I will agree with"? That doesn't even make sense since my entire argument has been based on the wording of the standard. What you're saying doesn't agree with the standard. I'm not even saying it's appropriate or the most correct thing to do, I'm just saying its not illegal, and you've yet to prove to me otherwise.

You're above post is you basically saying that you admit its not in the standard but somehow, you're still right. It's clear ad hominem.
@LB
Another valid point would be: The standard examples are to show what the standard is referring to. So if the standard had allowed void main() the example would have been:
1
2
3
4
int main() { /* ... */ }
int main(int argc, char* argv[]) { /* ... */ }
void main() { /* ... */ }
void main(int argc, char* argv[]) { /* ... */ }
Are we talking about the C standard?

ISO/IEC 9899:2011 (E) (hosted implementation):
5.1.2.2.1 Program startup

The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int

and with no parameters: int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared): int main(int argc, char *argv[]) { /* ... */ }

or equivalent10; or in some other implementation-defined manner.

If they are declared, the parameters to the main function shall obey the following constraints:

The value of argc shall be nonnegative.

argv[argc] shall be a null pointer.

If the value of argc is greater than zero, the array members argv[0] through argv[argc-1] inclusive shall contain pointers to strings, which are given implementation-defined values by the host environment prior to program startup. The intent is to supply to the program information determined prior to program startup from elsewhere in the hosted environment. If the host environment is not capable of supplying strings with letters in both uppercase and lowercase, the implementation shall ensure that the strings are received in lowercase.

If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name; argv[0][0] shall be the null character if the program name is not available from the host environment.

If the value of argc is greater than one, the strings pointed to by argv[1] through argv[argc-1] represent the program parameters.

The parameters argc and argv and the strings pointed to by the argv array shall be modifiable by the program, and retain their last-stored values between program startup and program termination.

10) Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as char **argv, and so on.


In a freestanding implementation, these rules do not apply.

1
2
3
4
5
6
7
8
9
10
typedef struct return_type { double* p ; char c[12] ; } return_type ; 

volatile return_type* main( int(*a)[23], int (*f)( int, double ) )
{
    f( *a[20], *a[5] ) ;
    
    static double d = 23.45  ;
    static return_type return_value = { &d, "hello" } ;
    return &return_value ;
}

ln -s main.cpp main.c
echo '------------------- freestanding --------------------------'
clang -std=c11 -Wall -Wextra -pedantic-errors -ffreestanding -c main.c && echo '*** ok ***' || echo '*** error ***'
gcc-4.8 -std=c11 -Wall -Wextra -pedantic-errors -ffreestanding -c main.c && echo '*** ok ***' || echo '*** error ***'
------------------- freestanding --------------------------
*** ok ***
*** ok ***


EDIT: http://coliru.stacked-crooked.com/a/ee933e6858e1e77d

And if this does not conform to the implementation-defined requirements for startup and termination, we can watch things burn.
Last edited on
No, we're talking about C89 and perhaps early revisions of C99. Or rather, any point in time where an official standard might have allowed "void main".

EDIT: Or, originally, I had mentioned C89 as not mentioning anything concerning the return type of main which people didn't agree with. I suppose that is the core of the argument.
Last edited on
There's a reason there are three standards after C89.
Neither of those examples state that it's illegal. Stroustrup was also talking about the C++ standard and how its not defined as legal in either C or C++. Again, it's not defined at all and is implementation defined.

Also, you should refrain from insulting anyone.

EDIT: Actually, he states that it's also stated in ISO C (which I believe is interchangeably used with C90 and basically ANSI C) but the clause isn't there. If he's talking about C99 and above, then fine. I don't recall any changes between C89 and C90.

EDIT2: Maybe I'm confusing what's considered ISO C...?

EDIT3: The main portion of this post was directed towards someone who has since removed their post.
Last edited on
NoXzema wrote:

Stroustrup was also talking about the C++ standard and how its not defined as legal in either C or C++.
Bjarne Stroustrup wrote:

The definition
void main() { /* ... */ }
is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1. A conforming implementation accepts
int main() { /* ... */ }
and
int main(int argc, char* argv[]) { /* ... */ }
A conforming implementation may provide more versions of main(), but they must all have return type int. The int returned by main() is a way for a program to return a value to "the system" that invokes it. On systems that doesn't provide such a facility the return value is ignored, but that doesn't make "void main()" legal C++ or legal C. Even if your compiler accepts "void main()" avoid it, or risk being considered ignorant by C and C++ programmers.
In C++, main() need not contain an explicit return statement. In that case, the value returned is 0, meaning successful execution. For example:

#include<iostream>

int main()
{
std::cout << "This program returns the integer value 0\n";
}
Note also that neither ISO C++ nor C99 allows you to leave the type out of a declaration. That is, in contrast to C89 and ARM C++ ,"int" is not assumed where a type is missing in a declaration. Consequently:
#include<iostream>

main() { /* ... */ }
is an error because the return type of main() is missing.


As others have pointed out, and as I said, if void main() was legal and part of the standard in C89 the examples they included to show what they meant would have also included the void main variants. The fact that it didn't means that int main is the standard and compilers that allowed void main just added them as part of their implementation of the standard.

NoXzema wrote:
Also, you should refrain from insulting anyone.

Insulting? Ignorance is always evident and needs no direct insults thrown for others to realize it is there.
Why would they include every possible use case in an example? If that's the case, why don't they do that for all other areas examples are used?
And for what it's worth, declaring someone as ignorant on such an edge case is unwarranted. I still think I'm right and can easily claim you're the ignorant one but I don't because it's not civil.

EDIT: Damn typos...
Last edited on
Your ignorance is solidified when the C++ language creators says
The definition
void main() { /* ... */ }
is not and never has been C++, nor has it even been C.

and you still argue it was part of it. I think that a guy that created C++, was friends and co-workers with C's creator and part of the Standard committee would know more about it than someone who reads and misinterprets the standard because it was absent of a word or phrase.
Last edited on
I've not once claimed its part of it. I've claimed that it's not worded to have an explicit required type so any type is allowed. That's the argument.

I don't really care what the creator says. I care about what is written down and the resources he makes those claims on. I don't think he's wrong either, I think you're just misinterpreting what the argument is and what Stroustrup claims.

Again, it was not explicitly disallowed to have void main in C89 or C90, whatever you wish to call it. That doesn't mean it was part of it either.
Last edited on
In addition, there are revisions in later standards that state explicitly the return type. If this wasn't an issue in C89 and C90, what was the purpose of making those revisions in later standards?
I'm with NoXzema in this dispute.

It is abundantly clear that the intent has always been: in a hosted implementation, main should defined with a return type of int.

If the text of the 1989 ANSI / 1990 ISO standard had unequivocally conveyed that intent, that part of the text would have been retained verbatim in the 1999 ISO standard.
Yeah I'm with Noxzema on this one. The C89 standard did not disallow the use of other return types for main. It may have been an oversight (hence why extra wording was added in latter versions) but under the C89 standard there is nothing (that I know of) to make void main illegal.
I'm with LB and BHX on this.
I believe Borges didn't read carefully as he just said X said A, when in reality X said B.
Easton completely missed the point too, did you even read the quote from the C89 draft?

But I believe we simply have a new troll on the forum, I just hope it leaves or changes attitude asap, especially since I've seen the 33-post-count topic.
Please state the part that you agree with and something to back up that part you agree with. I don't quite understand what you mean "X said A, when X said B" whenever the quote in question is missing.
Do you need some help reading english text?

He said YOU said main should be declared as returning int, when you made two pages of a discussion trying to prove the opposite.
That's something my 5 years old nephew would do.

Don't make us tell you every little particular.
You have a brain.
Use it.
You certainly haven't changed much...

Uh... well... I'll let JLBorges explain his own intent. Maybe you're right?
In fact I probably didn't change at all.
Maybe I even got worse.

Also I am already aware this is a 2nd account.
You already gave clues a decent number of replies ago.
Unless you want me to quote word-by-word, tho.
Last edited on
Pages: 12345