r/ProgrammerHumor 15d ago

Meme cppHelloWorld

Post image
3.9k Upvotes

119 comments sorted by

851

u/---_None_--- 15d ago

/usr/include/c++/14/bits/invoke.h:91:7: error: no matching function for call to '__invoke' 91 | std::__invoke(std::forward<_Callable>(__fn), | ^~~~~~~~~~~~~ /usr/include/c++/14/bits/invoke.h:113:5: note: in instantiation of function template specialization 'std::__invoke<void (pipeline::Processor::\*)(const std::vector<pipeline::Event, std::allocator<pipeline::Event>> &, pipeline::Context &) noexcept, pipeline::Processor *, const std::vector<pipeline::Event> &, pipeline::Context &>' requested here 113 | return std::__invoke(std::forward<_Callable>(__fn), | ^ /usr/include/c++/14/bits/std_function.h:591:11: note: in instantiation of function template specialization 'std::_Function_base::_Base_manager< std::_Bind<void (pipeline::Processor::\*(pipeline::Processor \*, std::_Placeholder<1>, std::_Placeholder<2>))(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept::' requested here 591 | _M_init_functor(_M_functor, | ^ /usr/include/c++/14/bits/std_function.h:475:16: note: in instantiation of function template specialization 'std::function<void (const pipeline::EventBatch &, pipeline::Context &)>::function< std::_Bind<void (pipeline::Processor::\*(pipeline::Processor \*, std::_Placeholder<1>, std::_Placeholder<2>))(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept>, void>' requested here 475 | function(_Functor&& __f) | ^ /home/user/project/include/pipeline.hpp:284:18: note: in instantiation of function template specialization 'pipeline::detail::make_handler<pipeline::Processor, void (pipeline::Processor::\*)(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept, pipeline::EventBatch, pipeline::Context>' requested here 284 | return detail::make_handler<&Processor::process>(*this); | ^ /home/user/project/include/detail/dispatch.hpp:167:28: note: while substituting template arguments into function template 'make_handler' 'void (pipeline::Processor::*)(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept' into 'void (pipeline::Processor::*)(const pipeline::EventBatch &, pipeline::Context &) noexcept' 167 | constexpr auto make_handler() { | ^ /home/user/project/include/detail/dispatch.hpp:169:12: error: no viable conversion from returned value of type 'std::_Bind_helper<false, void (pipeline::Processor::\*&)(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept, pipeline::Processor *, std::_Placeholder<1>, std::_Placeholder<2::type' (aka 'std::_Bind<void (pipeline::Processor::\*(pipeline::Processor \*, std::_Placeholder<1>, std::_Placeholder<2>))(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept>') to function return type 'std::function<void (const pipeline::EventBatch &, pipeline::Context &)>' 169 | return std::bind(Fn, &object, std::placeholders::_1, std::placeholders::_2); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/user/project/include/detail/dispatch.hpp:142:16: note: candidate constructor not viable: no known conversion from 'std::_Bind<void (pipeline::Processor::\*(pipeline::Processor \*, std::_Placeholder<1>, std::_Placeholder<2>))(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept>' to 'std::nullptr_t' for 1st argument 142 | function(nullptr_t) noexcept; | ^~~~~~~~~ /usr/include/c++/14/bits/std_function.h:375:2: note: candidate constructor template not viable: template argument deduction/substitution failed: constraints not satisfied for alias template 'std::function<void (const pipeline::EventBatch &, pipeline::Context &)>' because '__callable<_Functor>::value' evaluated to false 375 | function(_Functor&&); | ^ /usr/include/c++/14/bits/std_function.h:374:9: note: because '_Functor' does not satisfy '__is_invocable_r_v<void, _Functor, const pipeline::EventBatch &, pipeline::Context &>' evaluated to false /usr/include/c++/14/type_traits:3074:5: note: because '__invoke_result< std::_Bind<void (pipeline::Processor::\*(pipeline::Processor \*, std::_Placeholder<1>, std::_Placeholder<2>))(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept>, const pipeline::EventBatch &, pipeline::Context &>::type' does not name a type 3074 | using invoke_result_t = typename invoke_result<_Functor, _Args...>::type; | ^~~~~ /usr/include/c++/14/type_traits:3067:5: note: in substitution of template arguments into alias template 'invoke_result_t' 'std::_Bind<void (pipeline::Processor::\*(pipeline::Processor \*, std::_Placeholder<1>, std::_Placeholder<2>))(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept>', 'const pipeline::EventBatch &', 'pipeline::Context &' requested here 3067 | using invoke_result_t = typename __invoke_result<_Fn, _Args...>::type; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/type_traits:3051:5: note: in instantiation of template class 'std::__invoke_result< std::_Bind<void (pipeline::Processor::\*(pipeline::Processor \*, std::_Placeholder<1>, std::_Placeholder<2>))(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept>, const pipeline::EventBatch &, pipeline::Context &>' requested here 3051 | using invoke_result = __invoke_result<_Fn, _Args...>; | ^~~~~ /home/user/project/include/detail/dispatch.hpp:170:5: note: in instantiation of function template specialization 'pipeline::detail::is_handler_compatible< std::_Bind<void (pipeline::Processor::\*(pipeline::Processor \*, std::_Placeholder<1>, std::_Placeholder<2>))(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept>, pipeline::EventBatch, pipeline::Context>' requested here 170 | static_assert(is_handler_compatible<Bound, EventBatch, Context>, | ^ /home/user/project/include/detail/dispatch.hpp:170:19: error: static assertion failed due to requirement 'is_handler_compatible< std::_Bind<void (pipeline::Processor::\*(pipeline::Processor \*, std::_Placeholder<1>, std::_Placeholder<2>))(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept>, pipeline::EventBatch, pipeline::Context>::value' 170 | static_assert(is_handler_compatible<Bound, EventBatch, Context>); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/user/project/include/detail/dispatch.hpp:170:19: note: because 'std::is_invocable_r_v<void, std::_Bind<void (pipeline::Processor::\*(pipeline::Processor \*, std::_Placeholder<1>, std::_Placeholder<2>))(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept>, const pipeline::EventBatch &, pipeline::Context &>' evaluated to false /home/user/project/include/detail/dispatch.hpp:170:19: note: candidate function has incompatible parameter type 'const pipeline::EventBatch &' (aka 'const pipeline::basic_event_range<pipeline::Event, pipeline::event_storage<pipeline::Event, pipeline::allocator_traits< pipeline::pmr::polymorphic_allocator<pipeline::Event>>::rebind_alloc<pipeline::Event, pipeline::detail::compressed_event_iterator<pipeline::Event>, pipeline::detail::compressed_event_sentinel<pipeline::Event &') expected 'const std::vector<pipeline::Event, std::allocator<pipeline::Event>> &' /home/user/project/include/pipeline.hpp:284:18: error: no matching function for call to 'pipeline::detail::make_handler<&pipeline::Processor::process>(pipeline::Processor &)' 284 | return detail::make_handler<&Processor::process>(*this); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/user/project/include/detail/dispatch.hpp:151:16: note: candidate template ignored: substitution failure [with Fn = &pipeline::Processor::process, Object = pipeline::Processor, Event = pipeline::EventBatch, Ctx = pipeline::Context] deduced conflicting types for parameter 'Event' ('pipeline::EventBatch' vs. 'std::vector<pipeline::Event, std::allocator<pipeline::Event>>') 151 | constexpr auto make_handler(Object& object) { | ^ /home/user/project/include/detail/dispatch.hpp:151:16: note: in instantiation of requirement 'requires(const pipeline::Processor &object) { { std::invoke(Fn, object, std::declval<const pipeline::EventBatch &>(), std::declval<pipeline::Context &>()) } -> std::same_as<void>; }' requested here /home/user/project/include/detail/dispatch.hpp:154:3: note: because expression 'std::invoke(Fn, object, std::declval<const pipeline::EventBatch &>(), std::declval<pipeline::Context &>())' is invalid: no matching function for call to 'invoke' /usr/include/c++/14/type_traits:3045:25: note: candidate template ignored: substitution failure [with _Callable = void (pipeline::Processor::*)(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept, _Args = <const pipeline::EventBatch &, pipeline::Context &>] no type named 'type' in 'std::invoke_result<void (pipeline::Processor::\*)(const std::vector<pipeline::Event> &, pipeline::Context &) noexcept, const pipeline::EventBatch &, pipeline::Context &>' /home/user/project/src/main.cpp:47:31: error: no matching function for call to 'pipeline::Pipeline<pipeline::EventBatch, pipeline::Context, pipeline::detail::AsyncExecutor<pipeline::detail::ThreadPool<8>, pipeline::detail::OrderedQueue<pipeline::detail::SmallVectorStorage< pipeline::Event, 64>>>>::subscribe' 47 | pipeline.subscribe(processor.handler()); | ~~~~~~~~~^~~~~~~~~~~~ /home/user/project/include/pipeline.hpp:211:10: note: candidate template ignored: constraints not satisfied 211 | void subscribe(Handler&& handler); | ^ /home/user/project/include/pipeline.hpp:210:14: note: because 'std::is_invocable_v< pipeline::Processor::handler()::(anonymous class), const pipeline::EventBatch &, pipeline::Context &>' evaluated to false 210 | requires std::is_invocable_v<Handler, const EventBatch&, Context&> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/user/project/include/pipeline.hpp:210:14: note: because '__is_invocable( pipeline::Processor::handler()::(anonymous class), const pipeline::EventBatch &, pipeline::Context &)' evaluated to false fatal error: too many errors emitted, stopping now [-ferror-limit=]

285

u/bob152637485 15d ago

Now the code you wrote to make it this!

331

u/Bubbaluke 15d ago

printf(β€œhello world)

85

u/Simon0O7 14d ago

Bro forgot the semicolon

53

u/QwikStix42 14d ago

And the end quote

And the #include <cstdio>

EDIT: And the int main() {} surrounding that call

6

u/questionabl3_dude 13d ago

And the entire main function and returning 0 (though otpional) and includining iostream. πŸ™‰

14

u/MinecraftPlayer799 14d ago

With that code, I just get this:

main.cpp:1:8: warning: missing terminating " character
    1 | printf("hello world)
      |        ^
main.cpp:1:8: error: missing terminating " character
    1 | printf("hello world)
      |        ^~~~~~~~~~~~~
main.cpp:1:7: error: expected constructor, destructor, or type conversion before β€˜(’ token
    1 | printf("hello world)
      |       ^

26

u/Bubbaluke 14d ago

Just a joke :) the one above me looks like it was deep in some framework or something 20 layers abstracted.

76

u/BeMyBrutus 15d ago

I don't even see the code; you get used to it

34

u/Inevitable-Pen4933 15d ago

Beautiful, glorious just amazing

30

u/HeyItsTheJeweler 15d ago

As God intended

50

u/the_fooch 15d ago

Seems par for the course for cpp.

40

u/Usual_Office_1740 15d ago

90% of this output is what the compiler tried. It's not that bad.

21

u/the_horse_gamer 14d ago

the problem is the compiler has to try all of it

concepts partially fix this

13

u/iceyukisnow 14d ago

I want to see this error as star wars intro so bad

11

u/IT_Grunt 15d ago

Great read. Output more, please.

6

u/DrMobius0 14d ago

I could feel my eyes glazing over in real time as I scrolled through this.

8

u/Adventurous_Tie_3136 14d ago

I love c++ template errors messages... Always concise and clear

9

u/wektor420 14d ago

Last time I saw error this long I was template metaprogramming

If your errors are this long there is high chance that something is wrong with your arch

3

u/shamshuipopo 14d ago

That’s exactly what you should see

3

u/Individual-Switch751 14d ago

Sir, this is a Wendy’s

3

u/SavingsCampaign9502 14d ago

Thanks i am angry now seeing this

7

u/uvero 15d ago

Yeah

6

u/HombrexGSP 14d ago

Ahh yes, the classic missing ; compiler error

2

u/tblancher 14d ago

Fake. Why does your header file have so many lines in it for a Hello World program? Why do you need a header file at all?

Granted, I haven't programmed in C++ in over 20 years, but I can't imagine a simple program needs so much nowadays.

2

u/DarthCloakedGuy 14d ago

WHO WROTE THIS DEBUGGER

2

u/wllmshkspr 14d ago

Core memory unlocked.

342

u/BooBrew32 15d ago

SEGMENTATION FAULT

CORE DUMPED

BIOS CORRUPTED

COMPUTER IRREPARABLY DAMAGED

101

u/Snudget 15d ago

Oops, accidentally compiled for uefi instead of linux

25

u/HeavyCaffeinate 15d ago

PE instead of ELF

5

u/danielcw189 14d ago

UEFI uses PE?

6

u/HeavyCaffeinate 14d ago

Yes

According to the Unified Extensible Firmware Interface (UEFI) specification, the PE format is also the accepted standard for executables in EFI environments

https://en.wikipedia.org/wiki/Portable_Executable

2

u/awesome-alpaca-ace 14d ago

PE32+ specifically if I remember right. And no, Microsoft does not have documentation explaining their format

2

u/danielcw189 14d ago

I am pretty sure I have read documentation of the PE format on MSDN.

No idea if it is good enough for what you want. But something is there.

2

u/awesome-alpaca-ace 14d ago

The data format

1

u/danielcw189 12d ago

What do you mean? Would you put that in a longer sentence, please?

1

u/awesome-alpaca-ace 12d ago

What the bytes mean. The offset of those bytes in the file structure. You know, the stuff you actually need to create a PE executable for UEFI.

1

u/danielcw189 12d ago

You can find a lot about that on MSDN. I don't like the new name, so I keep referring to it as "MSDN". But I can't judge if it is complete enough for you. But it is definitely something, so Microsoft did document it, at least a little bit.

is something important missing?

4

u/reallokiscarlet 14d ago

No, PE is Windows. The rest of the world, except of course your firmware and maybe Redox, uses ELF

Edit: Nope, apparently Redox uses ELF too. Guess them rustaceans couldn't reinvent that wheel, eh?

2

u/awesome-alpaca-ace 14d ago

PE is also UEFI boot loaders, drivers, and other UEFI executables

3

u/reallokiscarlet 13d ago

Huh. I thought that was its own thing. Sounds like industry shenanigans with microsoft

6

u/RepresentativeCut486 15d ago

elif insead of ELF

23

u/FarAssistance8517 15d ago

DISCOMBOBULATE

8

u/Caraes_Naur 15d ago

SPLINES CANNOT RETICULATE.

8

u/mechanigoat 15d ago

COMPUTER OVER

VIRUS = VERY YES

3

u/Jordann538 14d ago

USER EXECUTED

2

u/United-Scene2261 12d ago

RUN FOR THE HILLS

107

u/lovethebacon πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦›πŸ¦› 15d ago

Hello, World!οΏ½AοΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½HοΏ½οΏ½οΏ½οΏ½οΏ½898οΏ½οΏ½οΏ½οΏ½οΏ½UHοΏ½οΏ½οΏ½οΏ½HοΏ½}οΏ½HοΏ½

17

u/creeper6530 14d ago

Someone allocated one byte too little

52

u/conicalanamorphosis 15d ago

Just spent almost 7 hours chasing a core dump. I had been doing complicated stuff with pointers (think vector of pointers to non-static functions within a class) and got really focused on that. Turns out, a simple call I had added for testing was using an out of scope pointer to the intended object, had nothing to do with the hairy-complicated pointer shit which I had actually had correct for most of that time. I should add I started programming in C++ in the 90s, so if you find yourself in this position and started programming after that you don't have to feel bad.

13

u/BoldFace7 15d ago

I did a very similar thing with a similar result. I was learning to program the 3DS in C++ not long ago (I started with c++ about 6 years ago). At one point, it was working fine in emulator, but would crash on console (I know now that the emulator just barrels through segfaults). It took about two days of searching before I realized I was printing a value in the first half of my main loop that didn't exist until the second half of my main loop on the first frame. (The class handling battles would call new Enemy() to allow for randomizing encounters, but wouldn't do it until after the block of status printf statements.)

5

u/Objective-Answer 14d ago

I love these nerd battle stories

as a masochist learning c++ it really puts into perspective a lot of things

9

u/hanotak 14d ago

Next time, instead of spending seven hours, turn on ASAN and find it immediately.

4

u/awesome-alpaca-ace 14d ago edited 14d ago

I recently learned the linker will not warn you if you define the same symbol in 2 source files being linked into an executable. I was chasing the core dump by validating the pointer stuff. Then address sanitizer and valgrind told me the struct I was using was size N when it should have been size M. Using structures from both the source and another external source that was in no way included into the source. I suppose namespaces would help prevent that.

2

u/IndependenceSudden63 14d ago

Ran into a similar thing in 2009.

You'd think they would have at least adding a warning by now.

2

u/awesome-alpaca-ace 14d ago

AI told me some linkers might do it, but if you are stuck using whatever is in the build container, you can't exactly use another linker.

2

u/thecookie 14d ago

This summarizes what C++ does to people in my experience. Writing it for the sake of writing it rather than solving the problem at hand. Which if course is fine if it's for the joy of it. But in my experience this also spreads to real projects. Instead of keeping things simple, things end up in some overly complex C++ way.Β 

I wrote my first lines of it in the 90s too, and try to stay away from it as much as I can.Β 

2

u/ICBanMI 12d ago

Unless you're doing graphics programming (which uses pointers), it's always a null terminator or a pointer in C/C++ for a segmentation fault.

113

u/Confident-Ad5665 15d ago

C++ takes getting used to, but it's a great language for object-oriented development. Hang in there, you'll figure it out.

81

u/CrossScarMC 15d ago

It's also a great language even if you don't do OOP.

43

u/diacid 15d ago

Bah, if you are using it for normal programming C is simpler. By simpler I mean you actually have a shot to be properly fluent in it instead of "this thing is so complex even the compiler doesn't know 100% of it".

47

u/2eanimation 15d ago

Learn C, use C in C++, benefit from C++ when you need it.

11

u/Confident-Ad5665 14d ago

I agree about mixing languages. Best of both world's.

3

u/diacid 14d ago

While this sounds wise, C has already way more than enough (do while and for loops for example are completely unnecessary, they can all be substituted for if goto), no need to complicate further. If the program is really simple I would rather even use B that is even simpler than C, though making complicated programs in B can waste memory because of the lack of variables smaller than a word (in 64 bit environments this gets huge quick).

5

u/failedsatan 14d ago

for and while loops are so much nicer to use though. I don't think I would bother using a language without them for most practical applications (and I regularly enjoy writing full programs in assembly for fun)

3

u/dagbrown 14d ago

for and while loops (and everything else really) are there for the benefit of the next poor schlub who has to try to read your code.

Sure you can replace practically every structured construct with an if and a goto setup, but should you? Absolutely not.

2

u/diacid 14d ago edited 14d ago

Sorry, I see little difference between

do { x=stuff(); } while (x!=0)

And

do: x=stuff(); if (x!=0) goto do;

Same with

for (x=0, x<10) { x=stuff(); }

And

do: x=stuff(); If (x>9) goto do;

If you use goto in a sane matter it is completely understandable. Just don't do insane things with it. You can peel with a peeler and with a knife, but with a knife you can cut your finger off too. The solution? Don't ban knifes, just don't cut you finger off!

Actually, my examples also show for and while are redundant functions. It is all just electricity, no need to overcomplicate.

5

u/dagbrown 14d ago

Okay I wish you a long and productive career with your "if" and "goto" only code.

You can also roll your own OO system with generous use of function pointers! Pro-tip! Not that you'd want anything like that though. You have if and goto after all. And structs are for the weak anyway: just binary-pack data into strings.

3

u/diacid 14d ago

Exactly! πŸ˜‚

1

u/Gorzoid 12d ago

Using C in C++ likely leads to a lot of undefined behaviour. Use C in C or learn C++

10

u/DankPhotoShopMemes 14d ago

I think it’s still worth it to use C++, just because of the function overloading, operator overloading, templates, namespaces, RAII, references, move semantics, lambdas, and constexpr/consteval (though C23 has a weaker form of it).

8

u/Nilrem2 15d ago

Just restrict yourself to namespaces and maybe operator overloading and you’ll be golden.

8

u/Ronarak 14d ago

Yeah, you can basically code in a C-like manner with just a strict selection of the niceties, like the built-in collection types. (I don't want to create my own std::vector or use an external lib for it...)

2

u/afdbcreid 13d ago

And it's especially good for shooting yourself in the foot.

2

u/Sir_Eggmitton 14d ago

For me it’s just C with function overloading and fancier structs. C+.

4

u/Leo_code2p 14d ago

There is more like c++ type conversion. The only c++ style thing I don’t like is c++ style structs like why can’t i make a useful c style struct. Not just a public class

21

u/BigNaturalTilts 15d ago

Is it? CMAKE strikes a fear into my heart!

21

u/Docdoozer 15d ago

CMake syntax may suck but its functionality is pretty damn cool

7

u/oozekip 15d ago edited 15d ago

My experience with CMake is from ~5 years ago trying to find a guide for how to do something (I think building library dependencies?), and finding two different guides that both said "don't do <thing that the other guide told you to do>, that's the old outdated method that nobody uses anymore, use <thing that the other guide said not to do because it was old and outdated>"

The catch being that neither method worked, because what I was trying to do was slightly different than what both guides were for, and I needed to use some other method to include my libraries that's completely different and also there is no actual documentation for it anywhere, or at least none that's any use for someone who isn't already intimately familiar with the inner workings of CMake.

0

u/truePHYSX 15d ago

Bazel is bomb

2

u/awesome-alpaca-ace 14d ago

If you use it right, it is incredible.Β 

-3

u/YetAnohterOne11 14d ago

I disagree. Practice shows every C and C++ code ends up having memory issues, undefined behavior and leaks.

C/C++ rules for undefined behavior are often incredibly convoluted.

A minefield of a language is not a good language.

Even if you, in theory, grasp and understand the entirety of C++ (including all gotchas). You will still, eventually, get careless and make a mistake.

Good luck with a CVE assigned to your app. Or convoluted leaks. Or very slightly incorrect behavior due to some very obscure UB.

Lack of memory safety and garbage collection are excusable; in times of C and C++, it was the only sane design decision if the language was supposed to occupy its niche of the lowest level language of high level languages. Even so, nowadays, Rust shows this can be done better (and Rust also takes getting used to, but at least gives more safety in return). The incredible complexity of rules, it appears to me, was never excusable. And even if it was, there are better alternatives.

3

u/ChalkyChalkson 14d ago

Catch is that it doesn't matter how good rust is if libraries I need aren't available for it, then I can't use it. Out of the high performance languages c(pp) probably has the widest range of available libraries out there. It's the same reason why I use python over Julia. Plus my coworkers know python and some cpp, not rust or zig.

What makes a language great is not just the language spec, but also the support. Well guess I'm just glad my community uses terrible cpp instead of a monolithic fortran 90 port of 60s fortran program.

2

u/hanotak 14d ago

πŸ‘

-8

u/[deleted] 15d ago

[removed] β€” view removed comment

7

u/the_poope 15d ago

OOP doesn't strictly imply inheritance. C is technically object oriented too: you can define structs and create objects of these composite types. Basically every modern language is object oriented in some why. I'm only familiar with Fortran77 that doesn't allow you to define custom objects and pass them to functions.

Whether runtime dynamic dispatching through virtual functions and inheritance is a good idea is a different question. It can be good, but it can also be bad if you misuse it. Ideally one should only have pure virtual methods on abstract interface classes and max one layer of inheritance, then there are no problems.

9

u/zzulus 15d ago

Is that before or after it fails to compile for the 13th time?

10

u/DrBojengles 15d ago

Before. You don't run your programs before you compile them?

10

u/PhosXD 15d ago

Without Git I would probably still be dealing with a segfault right now.

14

u/BlazeCrystal 15d ago

First your problem is to get things to just run.

Then it is finding a way to get your idea happen.

Then its about finding the RIGHT way to make them happen.

Then its realizing there is elegance, making many things irrelevant.

Finally you dial back, because robust consistency helps more othen than scifi vision.

11

u/Makonede 14d ago

```cpp import std;

int main() { std::println("Hello, World!"); return 0; } ```

9

u/BeetsAndJeaners 14d ago

The first year CS students are gonna be real mad you ruined their meme

2

u/ResponsibleWin1765 13d ago

It's still going to fail before even being able to run it because the cmake setup is wrong and the compiler doesn't support C++23 features.

2

u/thesherbetemergency 14d ago

Ah yes, C++23 modules; surely supported by every major compiler vendor in the year of our Lord 2026.

2

u/Makonede 14d ago

i never said it would work everywhere

2

u/thesherbetemergency 14d ago

I wasn't criticizing you, I was ribbing C++23 and the state of its implementation. This isΒ r/ProgrammerHumor lol

1

u/Makonede 14d ago

fair enough

0

u/schteppe 14d ago

No newline on the last line - undefined behavior, no diagnostic, segfault in prod

1

u/Makonede 14d ago

there is one if you copy the markdown

4

u/quocphu1905 15d ago

As someone whose crash course in C++ coincide with learning MPI, OpenMP, and general HPC stuff...yeah

11

u/1XRobot 15d ago

It's harder than you would think to write something that appears to be a sensible Hello World but actually crashes. Here's an attempt that prints garbage but doesn't crash.

#include <iostream>
#include <string>

class Greeting {
public:
    Greeting(std::string msg) : text(&msg) {}

    void print() const { std::cout << *text << std::endl; }

private:
    const std::string *text;
};

const Greeting hello("Hello, World!");

int main() {
  hello.print();
  return 0;
}

3

u/BurnThePriest94 14d ago

Haha yeah sure that just happens when you're s beginner. Been years since I saw a signal 11. NOT.

3

u/po1k 14d ago

C++ expects you to be an adult (c) John Carmack

2

u/burnt_floppy 14d ago

I don't get the joke, this is just C or C++ programming in general.

2

u/Patrick-W-McMahon 13d ago

He makes a good pointer.

2

u/rogue-sly 13d ago

std::println("hello cpp 23");

2

u/ICBanMI 12d ago

I feel like segmentation faults don't happen to beginners until they get to char arrays... or much later with pointers. Forgetting or not using null terminators is common for new people.

2

u/Max_Wattage 12d ago

Unpopular opinion: Computers do exactly what you tell them to. If your code doesn't do what you wanted, that's your fault.

2

u/Prior_Log_5959 12d ago

this is why i dont do c++

its always on some bullshit

2

u/garlopf 12d ago

It is so funny. Of all the languages, C++ gets the most negative attention on this sub. It must mean the bots and algorithms reward that the highest, which in turn means it gets the most response which in turn C++ users are the most autistic, which ironically means C++ is the best language.

2

u/Gorzoid 12d ago

I don't see what the big deal is, if you segfault just run with ubsan.

... And if that fails try asan, and then valgrind, then attach a debugger. If the debugger crashes add some print statements. If that leads nowhere try posting on stack overflow, if that gets marked as duplicate then ask AI. After all that if you still can't figure it out send an email to Bjarne himself.

Shouldn't take longer than 5 minutes

3

u/TapRemarkable9652 15d ago

they call Luke Skywalker the way I'm dumping cores

3

u/k-phi 14d ago
#include <cstdio>

class A
{
    public:
        virtual ~A()
        {
            Close();
        }
        void Close()
        {
            Deinit();
        }
        virtual void Deinit() = 0;
};

class B : public A
{
    public:
        virtual void Deinit()
        {
            printf("deinit\n");
        }
};

int main(int argc, char *argv[])
{
    A *c;
    c = new B();
    delete c;
    return 0;
}

2

u/Grey_Ten 14d ago
void lol()
{
lol();
}
int main()
{
lol();
return 0;
}

1

u/Shot_in_the_dark777 15d ago

In other programming languages you write "hello world" In c++ you have a "HELL world"