[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vr / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / asp / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / qst / sci / soc / sp / tg / toy / trv / tv / vp / wsg / wsr / x] [Settings] [Home]
Board
Settings Home
/g/ - Technology



Thread archived.
You cannot reply anymore.



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
>>
>>64722723
You don't. Void main is retarded.
>>
>>64722887
why?
>>
>>64722933
Programs have return values
>>
>>64722723
>>64722887
>>64722933
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.
>>
>>64722962
so?
>>
>>64722962
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.
>>
>>64722933
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
>>
>>64722723
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.
>>
File: maxresdefault.jpg (57 KB, 1280x720)
57 KB
57 KB JPG
>>64723003
dont bully me senpai!
>>
>>64722989
>>64722966
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.

>>64723005
You're all retards.
>>
>>64722989
>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
>>
>>64722989
What the fuck are you talking about?
>>
File: 1517500842611.png (14 KB, 478x523)
14 KB
14 KB PNG
>>64723021
#include <stdio.h>
#include <stdlib.h>

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);
}
>>
>>64722989
What the fuck are you on about
>>
>>64722989
What the fuck are you going off about?
>>
>>64723021
>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.
>>
>>64723065
>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.
>>
>>64722989
What the fuck?
>>
>>64722723
void main is not valid. If it compiles, it will just compile to
int main() {
/* code */
return 0;
}
>>
>>64723400
>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.
>>
>>64722723
Isn't comparing uninitialized variables undefined behavior?
>>
>>64722723

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.
>>
>>64723456
No, it won't. Very intelligent, handsome anon here had it right. Make sure you compliment him. He's very insecure.
>>64723400
>>
>>64722723
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).
>>
>>64723491
just noticed that.

Who the fuck would get this tattoo? I'm assuming that person at least took an introductory CS class or something
>>
>>64723491
in c it will just compare whatever is in the memory location. Not sure about c++

>>64723500
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;
}

>>
>>64723574
Wow. Just tried this. Will use this to troll.
>>
>>64722989
>It could be done as a WriteLine()
no, dude the returned value is for the OS loader so it "knows" how the program ended.
>>
>>64723574
Works fine in C
>>
>>64723538
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.

>>64723175
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.
>>
>>64723465
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.
>>
>>64723619
unsigned char main() {
return 0; // Works, int is 3 bytes too long
}
>>
>>64723647
>making false assumptions
>irrationally angry
Are you a femdumb or soyboy?
>>
>>64722989
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)
>>
>>64722989
This is why not learning C/C++ for your first language makes you a bad programmer
>>
>>64723750
Or learning C/C++ (in hindi)
>>
>>64722968
A program returns to the OS with an exit code/status. 0 being OK successfully closed, anything else being closed ungracefully.
>>
>>64722989
Jesús Christ /g/
>>
>>64722968
>>64723939

Sometimes an error message might say "...exited with a non-zero code" - the program's main returned a non zero integer indicated an error.
>>
>>64722723
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.

>>64722966
>>64722989
>>64723021
>>64723400
>>64723456
>>64723495
>>64723500
>>64723549

Reading this bullshit has made me dumber.
>>
>>64724046
Hop on over to the thread where /g/ has taken a pony embedded in a comment and blown it all out of proportion. /g/ can get dumber friendo.
>>
>>64722723
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
>>
>>64723456
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.
>>
>>64724013
This need to be higher up.
>>
>>64724379
>why tattoo artists shouldn't code
>Using preprocessor notation as comment
>>
>>64722723
Debug and useful features
>>
>>64722989
what le fuck??? xd
>>
>>64722723
Because C++ demands it.
>>
>>64723300
You’re missing a return in main though lol
>>
>>64722723
If you look closely it looks like he is using the equality operator instead of assignment.

Love == Life;
Life == Gabi;
Gabi == Love;
>>
>>64722723
>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?
>>
>>64724839
The worst part is
>using namespace std;
in permanent ink
>>
>>64722723
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.
>>
>>64724909
what about float main?
>>
>>64723574
why not
char main(void) {
// dicks
return('A');
}

??????

gcc only gives a warning
>>
>>64724839
And he used the assignment operator instead of equality in his while loop.
>>
>>64724939
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.
>>
>>64724909
I was going to say the same thing until I just compiled and ran a program with this setup >>64725056
>>
>>64722723
>He returns from main
Not just calling ExitProcess
>>
>>64723300
>i don't understand how operating systems work
pic related, i assume?
>>
>>64723499
>i don't know how to read
what is it with brainlets and dubs in this thread?
>>
>>64722933
Kinda against "modern" OSes, every one expects a process to return a status code after its execution.
>>
>>64723021
Take a look at how the function calls work in assembly.
>>
>>64725111
>ExitProcess
Windowsfag detected.

Also
>calling exit instead of return
Messes with RAII.
>>
>>64722989
What the heck are you all about?
>>
>>64722723
void main is wrong
your program entry point has to return an integer
>>
>>64726118
>your program entry point has to return an integer
It doesn't have to, no.

>>64724909
>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.
>>
>>64726131
>It doesn't have to, no.
It isn't required to, but it really should.
>>
>>64726136
>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.
>>
>>64726145
>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.
>>
>>64726158
>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.
>>
>>64726170
>The only two correct main signatures in C are
int main(int argc, char** argv, char** envp);


Also
>const char** argv
lol no
>>
File: .jpg (44 KB, 706x720)
44 KB
44 KB JPG
>>64726173
>non c99
>>
>>64726181
>non c99
Pic related
>>
File: wrong.gif (704 KB, 480x287)
704 KB
704 KB GIF
>>64726170
>
const char** 
>>
>>64726096
Fine I'll call SendMessage(HWND_BROADCAST, WM_CLOSE, 0, 0); instead.
>>
Because the first one isn't UB you fucking retard.




Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.