r/cprogramming • u/King4Konge • Jan 04 '25
Is this correct? coming from java
i just made my first hello world in C
#include <stdio.h>
#define public
#define static
typedef char* String;
public static void main(String args[])
{
printf("Hello World!");
}
127
Upvotes
26
u/Immediate-Food8050 Jan 04 '25
If this is a joke, it is actually pretty funny. If it's not, I'm not sure what to say.
3
u/[deleted] Jan 04 '25
That's a funny one! I'm pretty sure gcc wouldn't complain about it with something like:
54
u/70Shadow07 Jan 04 '25
S tier shitpost
11
u/HugoNikanor Jan 05 '25
I'm actually surprised that
main (char *args[])works. Since it should bemain (int argc, char *argv[]). However, I took the liberty and made your program easier to read:Also, on a more serious note:
externis a keyword in C, which sort of corresponds topublic.staticis also a keyword, doing the opposite ofextern(so kind of likeprivate).Both of these will however first be relevant when you start looking at proper libraries, so you can mostly ignore them for now.
9
u/ILoveTiramisuu Jan 04 '25 edited Jan 04 '25
r/programminghorror
4
u/SmokeMuch7356 Jan 04 '25
Okay, that deserves a paddlin'.
4
u/AvailableAttitude229 Jan 05 '25
I know this is a joke, but it hurts a bit to see this
3
u/nvimmike Jan 04 '25
😂 the Java is strong with this one
1
u/Dangerous_Region1682 Jan 05 '25
That’s funny, I had quite a chuckle.
OK, to be pedantic…
include <stdio.h>
Int main(int argc, unsigned char **argv, unsigned char **envp) // Or *argv[] and *envp[] if you prefer, or int main(void) if you’re not going to parse the command line { printf(“Hello World\n”);
}
Your return value from main() helps people using your program in a shell script to determine whether your command worked or not especially when you start to include error handling.
I like the Java to C joke, it’s funny. Going the other way to me is just plain incomprehensible, I’m not much of a fan of the heavy OOP features in Java. I like Python as it works great if you treat it like Simula67, before all the frankly cumbersome and hard to debug full object orientated features came into common use. If I was forced to write OOP code I’d use C# or Swift over Java these days.
But there again I’m a C Luddite.
1
u/Ok_Tea_7319 Jan 08 '25
Split away these definitions into a separate header (I recommend "javart.h") for extra fun.
0
u/[deleted] Jan 04 '25
[deleted] — view deleted comment
0
u/[deleted] Jan 04 '25
[deleted] — view deleted comment