Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
return (0);
I usually don’t use parentheses for single values like that, but whatever passes code review. -
orhun12535y@bkwilliams Exactly, return is a statement. It seems like a function in here.
I don't know who writes return like this. -
@orhun I do - although I know it isn't necessary. I just like it that way. Except if I get into an existing codebase where it's without parentheses, then I'll keep the style for consistency.
-
orhun12535y@Fast-Nop That's reasonable. At least you're not saying "why this is so important" like my teacher.
ugh -
return (a >= b ? 0 : 1);
return (a >= b);
They look the same, but one of them is probably banned in your company. -
Pyjong10935yNope nothing weird going on here.
return(0) is xor eax,eax; ret, this actually makes more sense if assembly is your first language. -
Does main require arguments?
I usually see main like this:
int main(int argc, char* argv[])
Are those absolutely required? I did a search but all I saw was conflicting statements.
That is why I originally posted "no argument here". -
Pyjong10935y@orhun there is no "return value" instruction. return statement translates to load to whatever register dedicated for holding the return value and ret which loads program counter to address after function call. So technically return(0) is the simplest function.
-
@Demolishun main can be a void function - however, using empty parentheses leaves the argument question open, i.e. allows any arguments.
-
@Fast-Nop yes, that is why one is banned and you should always test before pushing to prod.
-
Root825575yAdd main args, kill the parenthesis on return. Printf really should include a newline, too.
-
olback109815y@Root summed up everything quite nicely here.
Side note: main takes 3 arguments, not a whole lot of people know that 🤷♂️ -
@olback No it doesn't. argc and argv, that's as per the standard. You have envp also - but only under Unix systems, so that's not "C". It's implementation defined and not portable.
-
@olback There are a few more OS than Windows and Unix. Not quite as many as it used to be, but still.
-
nitnip18145yWhen I was taught C, the hello world code used `fprintf(stdout, "Hello World\n")`. It was cool to know fprint before printf.
Related Rants
Do you sense something weird on this dead simple code?
The teacher showed a similar code recently in my C class. It was weird to me since I know C for years. I want to know what you guys think about it.
question
c
weird
standards