I think anyone who sees my C++ code can tell I was a C# developer first mainly because of how I write most of my utility methods - wrap them in a class if they’re logically grouped and make all member functions static. Just makes it more familiar to my C# monkey brain.
as someone who is learning C++, I definitely just use the same type of structure as my Java code (classes, naming, formatting, etc etc). It's way simpler than learning the actual "proper" way to do it
I think that technically makes your code undefined, but I doubt someone doing that cares.
It does? Where does it say that? AFAIK the Preprocessor has almost no undefined behavior. (only one I know of is edge cases with literals that look like they may be numbers but aren't)
Maybe that's just C++, but I've heard that redefining keywords is UB. Though that might've been if any standard library headers are included after redefining a keyword.
Yeah, C++ apparently explicitly mentions this to be UB (redefining a keyword when you are including headers). C doesn't AFAIK, and in both redefining keywords itself is not directly problematic. (similar to how int x; itself is not problematic - it's only problematic if you don't assign a value before accessing it)
Idk why this just reminds me that I got in trouble for explicitly stating void parameters for functions with zero parameters when I was in uni. I’m still pissed about it today because the professors defense was “well it’s the same thing so you might as well put the easier one” like bitch did you not read the textbook you assigned to us? It clearly states empty parentheses are bad practice and then gives a laundry list of reasons why.
It's complicated though. int f(void) was added in the first C iso standard (aka ANSI C) to distinguish functions with no parameters from K&R-style function declarations. But, well, K&R-style functions declarations are essentially gone by now. Add to that that C++ never used (void), and you see why it could make sense to drop it.
Reminds me of "polyglot programs", single source file programs that compile/execute correctly in multiple compilers/languages. E.g. google gave me this example, which will do essentially the same in Python, Bash, Perl and Ruby (I haven't checked!)
Edit: example was AI slop (from Google) and has been removed. Actual example below.
That's a poor AI attempt at a polyglot. It's not. It's a bash script that uses separate bash, perl, and python commands to execute different code snippets. It answered the question: "write a 'hello world' program in three different languages" which is not a polyglot.
Here's a real polyglot that actually runs in bash and Python.
Yeah, if I'd taken even a second to look I'd have seen. As I said, copy/pasted from Google. Shouldn't have bothered. Not like I was going to write one myself for a quick post though. I'll remove it.
You can also have the extern struct only available in the header, and then define and assign static functions in a source file. That way it would actually prevent name collisions like proper modules
356
u/Gadshill Mar 25 '26
When a Java developer is forced to write C, but they’re still in the denial stage.
121
u/_AscendedLemon_ Mar 25 '26
OK, now change
int mainintopublic static void main43
u/Yep-iamjeetard Mar 25 '26
Ahh yes, C The easiest to obfuscate language of all
22
u/definitelyfet-shy Mar 25 '26
Thanks I hate it
11
u/hongooi Mar 25 '26
Į̵͖͎̎̄t̷̨͎͑̉̓͝'̸͈̝̼͍͋̎͐͠s̷̮̳̾̂̏̕ ̶̼͚̑̇̒̃b̴̬̟̬͐̎̆e̵̹̊a̴̱͚͑ũ̷̲̮̘͑̈́ͅt̷̮̀͐̚͝ị̷̘̺̍̌̏f̸̧̮̫̥̄u̴̦̭̮̇͑̆͂ͅl̶̘͎̣̽̌
11
u/Mr_FalseV Mar 25 '26
This isn’t polyglot code, this is a hostage situation.
4
u/not_some_username Mar 25 '26
That’s probably what Java was doing at some point
3
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Mar 25 '26
System.out.println()would take a little more effort. I'm pretty sure the Java version gives you much less control over formatting thanprintf() too.2
u/KalaiProvenheim Mar 25 '26
What is wrong with you????
2
u/ironnewa99 Mar 26 '26
Idk why this just reminds me that I got in trouble for explicitly stating void parameters for functions with zero parameters when I was in uni. I’m still pissed about it today because the professors defense was “well it’s the same thing so you might as well put the easier one” like bitch did you not read the textbook you assigned to us? It clearly states empty parentheses are bad practice and then gives a laundry list of reasons why.
Rant over, sorry for the random rant.
4
u/HashDefTrueFalse Mar 25 '26 edited Mar 25 '26
Reminds me of "polyglot programs", single source file programs that compile/execute correctly in multiple compilers/languages. E.g. google gave me this example, which will do essentially the same in Python, Bash, Perl and Ruby (I haven't checked!)
Edit: example was AI slop (from Google) and has been removed. Actual example below.
1
u/TheChief275 Mar 25 '26
You can also have the extern struct only available in the header, and then define and assign static functions in a source file. That way it would actually prevent name collisions like proper modules
1
u/shut_up_if_your_dumb Mar 25 '26
TIL that you can define nested structs like that
1
u/Randolpho Mar 25 '26
C. The
#includeandint main(void)is are dead giveaways.What do I win?
1
u/Business_Welcome_870 Mar 25 '26
Cool
1
u/Cursor_Gaming_463 Mar 25 '26
Well, fuck me.
1
u/HeavyCaffeinate Pronouns: She/They Mar 26 '26
I've never seen someone initialize a struct like that
1
u/CHAiN76 Mar 27 '26
Namespace envy.
1
u/Luxy2008 Mar 27 '26
Cava
1
u/Extreme_Dependent_63 Mar 25 '26
When a Java dev wants the code to run fast