void main(){...} is not in the standard, but works on both MSVC and GCC (with warnings). I think it works on both C/C++, but you really shouldn’t use it in production. Just use int main(void){...} , without any return value, which is permitted in the standard, and will return success iirc.
i will never forgive C for making the type syntax be
char* args[]
instead of the much more reasonable
&[char] args
it also bothers me that char* args[] and char c are “the same type” in the sense that the compiler lets you write
char c, *args[5];
with no problems. i think the C languages would be way easier to learn if they had better type syntax. don’t even get me started on C++ adding support for
I personally think that C++ can be beautiful. For example: std::filesystem::path overrides the / operator, for specifying parent paths. It’s the same as Kotlin’s OKIO and Pythons standard pathlib.
char **args can just mean you have a pointer which points to an address, and at that address, you can get a second address. Follow the second address, there is a char saved there.
On the other hand, char *args[] means " follow this address to find a list of characters".
@racketlauncher831 As far as the C compiler is concerned, there is literally no difference between those two notations. If you declare a function parameter as an array (of T), the C compiler automatically strips the size information (if any) and changes the type to pointer (to T).
(And if we're talking humans, then char *args[] does not mean "follow this address to find a list of characters" because that's the syntax for "array of pointers", not "pointer to array".)
17 Comments
barubary@infosec.exchange · 71 pts · 1y
Strictly speaking, it should be
lily33@lemm.ee · 39 pts · 1y
That is why I use just
int main(){...}without arguments instead.Bogus5553@lemm.ee · 28 pts · 1y
Any
void main(){...}enjoyers?stebo02@lemmy.dbzer0.com · 7 pts · 1y
barubary@infosec.exchange · 9 pts · 1y
@stebo02 @Bogus5553 Neither of them require a return value, but
void mainisn't legal C++.stebo02@lemmy.dbzer0.com · 2 pts · 1y
Bogus5553@lemm.ee · 4 pts · 1y
void main(){...}is not in the standard, but works on both MSVC and GCC (with warnings). I think it works on both C/C++, but you really shouldn’t use it in production. Just useint main(void){...}, without any return value, which is permitted in the standard, and will return success iirc.Buddahriffic@lemmy.world · 2 pts · 1y
It will also give an error if you try to add a return value anyways.
Thorry84@feddit.nl · 2 pts · 1y
while (true) {...}CausticFlames@sopuli.xyz · 1 pts · 1y
int main(void) { . . . }for me!HStone32@lemmy.world · 19 pts · 1y
Safe code is a skill, not a feature.
affiliate@lemmy.world · 6 pts · 1y
i will never forgive C for making the type syntax be
instead of the much more reasonable
it also bothers me that
char* args[]andchar care “the same type” in the sense that the compiler lets you writewith no problems. i think the C languages would be way easier to learn if they had better type syntax. don’t even get me started on C++ adding support for
barubary@infosec.exchange · 7 pts · 1y
@affiliate Hey, you didn't even mention that
char *args[]actually meanschar **argsin a parameter list.affiliate@lemmy.world · 5 pts · 1y
god, what a beautiful language. it brings a tear to my eye
Bogus5553@lemm.ee · 3 pts · 1y
I personally think that C++ can be beautiful. For example:
std::filesystem::pathoverrides the/operator, for specifying parent paths. It’s the same as Kotlin’s OKIO and Pythons standard pathlib.racketlauncher831@lemmy.ml · 2 pts · 1y
It could, but not necessarily.
char **argscan just mean you have a pointer which points to an address, and at that address, you can get a second address. Follow the second address, there is acharsaved there.On the other hand,
char *args[]means " follow this address to find a list of characters".barubary@infosec.exchange · 3 pts · 1y
@racketlauncher831 As far as the C compiler is concerned, there is literally no difference between those two notations. If you declare a function parameter as an array (of T), the C compiler automatically strips the size information (if any) and changes the type to pointer (to T).
(And if we're talking humans, then
char *args[]does not mean "follow this address to find a list of characters" because that's the syntax for "array of pointers", not "pointer to array".)merthyr1831@lemmy.ml · 3 pts · 1y
counterpoint: all code is unsafe. retvrn to abacuses
Ziglin@lemmy.world · 3 pts · 1y
But I was hit over the head with one, that wasn't safe either!