Why use int main over void main?
Why use int main over void main?
There's shit tattoos, then there's this...
surely that must be hell
is that real? if yes then this is worse than being a NEET permavirgin
I seriously hope the guy was drunk when he got that tattoo, otherwise he should be bullied to hell
You don't. Void main is retarded.
why?
Programs have return values
new to programming. Isn't the Int/Void thing a return type? If so, then I guess it just depends on whether you want main to return something or not.
so?
True, but not all programs need that value to be returned in a return statement in main. It could be done as a WriteLine() in C#, or I guess a printf in C.
ask google, /sqt/, SO
literally just googled your dumb question and got it answered on SO
sage
Sometimes it's useful for the system (or external programs) to be able to see that "0" to ensure that the program terminated correctly without any errors. Also everyone in this thread is a brainlet
void is such a stupid concept, return nothing?
what does that even mean? Clearly it returned something, else how would we know it finished?
Sane programming languages return the unit to indicate that they are done doing whatever they had to do.
dont bully me senpai!
Just because you don't return a value from main, doesn't a value isn't returned. It will compile. Check the exit status after it terminates.
You're all retards.
>It could be done as a WriteLine() in C#, or I guess a printf in C.
No it can't be. What the fuck are you talking about?
>If A = B = C = A
literally why
What the fuck are you talking about?
#include
#include
void usage(char *);
int main(int argc, char **argv) {
if(argc == 1)
usage(argv[1]);
}
void usage(char *prog_name) {
printf("There is no reason this needs to or will return a value to main, retard\n", prog_name);
exit(1);
}
What the fuck are you on about
What the fuck are you going off about?
>Clearly it returned something, else how would we know it finished?
Seriously?
>Sane programming languages return the unit to indicate that they are done doing whatever they had to do.
I don't even
Exit status.
>doesn't a value isn't returned. It will compile.
Yeah because the compiler and the guy who wrote it are way smarter than you, and will have the compiler put in exit status codes anyways.
What the fuck?
void main is not valid. If it compiles, it will just compile to
int main() {
/* code */
return 0;
}
>n-no you're a r-retard *sniff*
Lol, relax. I'm sure your mom will tell you you're special. Give her a call, and don't fret so much.
Isn't comparing uninitialized variables undefined behavior?
I can't even imagine how much pussy this guy is going to get. Next he should tattoo the GPL on his ass, like Stallman.
No, it won't. Very intelligent, handsome user here had it right. Make sure you compliment him. He's very insecure.
I think the return value can indicate successful program completion. I know our instructor told us return 0; meant normal program termination for Windows, but for some OSes you had to return 1.
I would presume then that void would be for trivial programs whose failure to execute are of no bearing ("hello world" being one).
just noticed that.
Who the fuck would get this tattoo? I'm assuming that person at least took an introductory CS class or something
in c it will just compare whatever is in the memory location. Not sure about c++
void is more for functions separate from main. But by it's nature main is a function so you can use void on it, but it's not something you should do, it's better practice to just return 0 whatever the program
Return float is the new meta.
float main() {
// do stuff
return 0.0;
}
Wow. Just tried this. Will use this to troll.
>It could be done as a WriteLine()
no, dude the returned value is for the OS loader so it "knows" how the program ended.
Works fine in C
Only retards get tattoos, and only even bigger retards get the names of people they love tattooed on them. Then 2 years later she leaves you for Tyrone and you have her name tattooed on your arm like a retard.
His while loop just sets them all to true, which makes the loop run forever. He's trying to say that his love for this woman is infinite. But then he spells it out for us in a comment as if anyone with a brain couldn't figure out what it means.
No, the compiler will literally compile it to use return status. Just like how it will compile out and optimize 98% of your shitty for loops and unnecessary conditional branching.
unsigned char main() {
return 0; // Works, int is 3 bytes too long
}
>making false assumptions
>irrationally angry
Are you a femdumb or soyboy?
Hi Rajeesh, how is the weather in Thiruvananthapuram
some freestanding environments don't need to return anything from main. especially if main never "finishes". not sure if that violates some sort of C standard or what but i've seen it plenty of times.
>using namespace std
>std
kek
(and yes i know it means standard, nigger)
This is why not learning C/C++ for your first language makes you a bad programmer
Or learning C/C++ (in hindi)
A program returns to the OS with an exit code/status. 0 being OK successfully closed, anything else being closed ungracefully.
Jesús Christ Sup Forums
Sometimes an error message might say "...exited with a non-zero code" - the program's main returned a non zero integer indicated an error.
To return a value to the terminal after the program completes, usually returning and int that just says it succeeded. Not needed in modern langs, void is fine
Holy fuck where did all the retards in this thread come from.
Reading this bullshit has made me dumber.
Hop on over to the thread where Sup Forums has taken a pony embedded in a comment and blown it all out of proportion. Sup Forums can get dumber friendo.
To catch error messages by returning stuff other than 0 if you are running your own error checking system.
Other than that nobody really gives a shit
No... this is so far fucking wrong
GOD DAMMIT, SEPARATE YOUR FUCKING '=''s
1==1
# should be
1 == 1
I feel like these are the same people that use u, ur, tho, and doe unironically.
This need to be higher up.
>why tattoo artists shouldn't code
>Using preprocessor notation as comment
Debug and useful features
what le fuck??? xd
Because C++ demands it.
You’re missing a return in main though lol
If you look closely it looks like he is using the equality operator instead of assignment.
Love == Life;
Life == Gabi;
Gabi == Love;
>declares variables without values
>tests equality for Life, Love, Gabi (I believe this will return false for each
>Creates a loop that assigns each undeclared variable to each other AND uses an undeclared variable, most likely not even allowing the program to compile
>Even if me was declared the program would only print "Eternal love..." once
Did I get that right?
The worst part is
>using namespace std;
in permanent ink
Sane compilers like GCC only accept int main. void main is invalid because you need to give the OS an integer return code to indicate execution status.
what about float main?
why not
char main(void) {
// dicks
return('A');
}
??????
gcc only gives a warning
And he used the assignment operator instead of equality in his while loop.
Probably would work.
The thing under the hood is that when you "return" a number, you actually put this number on the stack, and the OS expects to fetch this number from the stack, and if the number is not there, undefined terrible things can happen.
Or the OS may just be programmed to detect the retarded exit and try to clean it up.
I was going to say the same thing until I just compiled and ran a program with this setup
>He returns from main
Not just calling ExitProcess
>i don't understand how operating systems work
pic related, i assume?
>i don't know how to read
what is it with brainlets and dubs in this thread?
Kinda against "modern" OSes, every one expects a process to return a status code after its execution.
Take a look at how the function calls work in assembly.
>ExitProcess
Windowsfag detected.
Also
>calling exit instead of return
Messes with RAII.
What the heck are you all about?
void main is wrong
your program entry point has to return an integer
>your program entry point has to return an integer
It doesn't have to, no.
>void main is invalid because you need to give the OS an integer return code to indicate execution status.
That's literally implementation defined behaviour.
>It doesn't have to, no.
It isn't required to, but it really should.
>It isn't required to, but it really should.
Well, it's not necessary if you call exit() with a status. In that case, void can be whatever return type it wants to be, because it's never going to return.
>Well, it's not necessary if you call exit() with a status. In that case, void can be whatever return type it wants to be, because it's never going to return.
I would still put the int return type there for clarity, since that is what exit returns.
Especially if more than a single person is working on the program.
>I would still put the int return type there for clarity, since that is what exit returns.
exit() doesn't even technically return though.
The only two correct main signatures in C are
int main(int argc, const char** argv)
and
int main(void)
Another thing is that correct programs have return values. Embedded shit is another thing, but i'd still use int, even though it won't affect anything.
>The only two correct main signatures in C are
int main(int argc, char** argv, char** envp);
Also
>const char** argv
lol no
>non c99
>non c99
Pic related
>const char**
Fine I'll call SendMessage(HWND_BROADCAST, WM_CLOSE, 0, 0); instead.
Because the first one isn't UB you fucking retard.