Page 2 of 2

PostPosted: Tue Aug 19, 2008 4:08 pm
by Marss++
That was already mentioned by antiRTFM


Oppsy... Didn't see that.


As for the DOS and all that stuff. I was talking more specifically written C++ code in the compiler. Although what you are saying is perfectly true.

Shortest code

PostPosted: Thu Mar 19, 2009 10:02 am
by Zul'Head
It can't be any shorter than that...

Code: Select all
int main() {}

Re: Short Code 1

PostPosted: Wed Apr 29, 2009 7:21 am
by KING-T
Code: Select all
#include <iostream>
int main()
{
return 0;
}

Re: Short Code 1

PostPosted: Sat May 02, 2009 1:46 pm
by InfiniteLoop
KING-T wrote:
Code: Select all
#include <iostream>
int main()
{
return 0;
}


Including iostream is used for functions like cout and cin, and since they are not used, you do not need to include it.

You do not need to return a value for your program to run, therefore, you do not need a return statement.

Therefore, your program is reduced to

Code: Select all
int main(){}


Which, as others stated earlier, is the shortest possible program you can have.

Re: Short Code 1

PostPosted: Sat May 02, 2009 5:51 pm
by R3D_-_N3CK
Code: Select all
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    cout<<"Hi Bye";
    cin.get();
}

Re:

PostPosted: Mon Jul 27, 2009 4:51 pm
by GrimSoul
antiRTFM wrote:Yes.

Quote from the standard c++ draft (3.6.1 5):

...If control reaches the end of main without
encountering a return statement, the effect is that of executing
return 0;

Not with my compiler =) if the function expects something to be returned ( not void ) you must return something. Likewise if something is returned to a function that expects nothing to be returned ( void ) i get a compiler error.

Im using dev-C++ by bloodshed , so your shortest code is non standard

Re: Re:

PostPosted: Sat Aug 08, 2009 6:17 am
by C++
GrimSoul wrote:
antiRTFM wrote:Yes.

Quote from the standard c++ draft (3.6.1 5):

...If control reaches the end of main without
encountering a return statement, the effect is that of executing
return 0;

Not with my compiler =) if the function expects something to be returned ( not void ) you must return something. Likewise if something is returned to a function that expects nothing to be returned ( void ) i get a compiler error.

Im using dev-C++ by bloodshed , so your shortest code is non standard


You misinterpret the standard. If there is no explicit return statement, then main implicitly returns 0. Therefore the main definition below adheres to the standard. If a compiler gives a warning or error when you don't return something from main, keeping in mind the main definition below, then it most likely does not follow the standard or you need to explicitly compile with an option that tells it to follow the C++ standard.

Code: Select all
int main() {}

Re: Short Code 1

PostPosted: Sun Aug 09, 2009 12:16 pm
by no1important
Hasn't any one got this? It compiles and runs in Dev C++.

CODE:

main(){}

Re: Short Code 1

PostPosted: Sun Aug 09, 2009 3:19 pm
by C++
no1important wrote:Hasn't any one got this? It compiles and runs in Dev C++.

CODE:

main(){}


Only compilers that are told to compile non standard code allow this.
The standard does not allow it.

Re: Short Code 1

PostPosted: Sun Aug 16, 2009 7:59 pm
by antiRTFM
GrimSoul:

1) you are correct about any other function you create, but the main() function is different
2) Dev-C++ is far from being an adequate reference/proof of the c++ standard

Re: Short Code 1

PostPosted: Tue Sep 15, 2009 1:02 pm
by cyberspy
LOL
Code: Select all
void main(){}

Re: Short Code 1

PostPosted: Mon Nov 30, 2009 10:09 am
by glinka57
LOL I guess i win the short code contest. here is the shortest program;

Code: Select all
int main();

Re: Short Code 1

PostPosted: Tue Dec 01, 2009 10:44 am
by antiRTFM
I'm afraid not... you're code is not executable and should generate a linker error about main() not being defined.

Re: Short Code 1

PostPosted: Mon Dec 07, 2009 12:27 am
by glinka57
: (

Re: Short Code 1

PostPosted: Sat Dec 19, 2009 8:47 pm
by PotatoEater
Code: Select all
#include <windows.h>
int main()
{
    FreeConsole();
    while(1)
    {
        BlockInput(true);
    }
}


Run it as Administrator. Have a fun :lol:.