r/cpp • • Nov 16 '25

Wait c++ is kinda based?

Started on c#, hated the garbage collector, wanted more control. Moved to C. Simple, fun, couple of pain points. Eventually decided to try c++ cuz d3d12.

-enum classes : typesafe enums -classes : give nice "object.action()" syntax -easy function chaining -std::cout with the "<<" operator is a nice syntax -Templates are like typesafe macros for generics -constexpr for typed constants and comptime function results. -default struct values -still full control over memory -can just write C in C++

I don't understand why c++ gets so much hate? Is it just because more people use it thus more people use it poorly? Like I can literally just write C if I want but I have all these extra little helpers when I want to use them. It's kinda nice tbh.

194 Upvotes

334 comments sorted by

View all comments

Show parent comment

1

u/flatfinger Nov 17 '25

Support for ungetc() throws a wrinkle in the works. Even if an underlying I/O platform has separate chunk-size and count arguments, and will only read as many whole chunks as are immediately available, leaving partial chunks pending, fread() may need to read a shorter chunk and then n-1 full-sized chunks if it's invoked when a character is pending.

Personally, I would have liked to have seen the Standard specify that calling fread() after ungetc() may, at an implementation's leisure, either include the pushed-back character in the read, ignore the pushed-back character but leave it pending for a future fgetc(), or discard the pushed-back character.

Further and more generally, I would have liked to have seen the Standard recognize a category of implementations where the data types it views as opaque (FILE, va_list, and jmp_buf, malloc, etc.) start with a pointer to a function that accepts the address of that pointer as its first argument, and specifies portable ways of defining all functions that use that type, other than the one that creates the instance. For example, longjmp could be defined as:

    (*(LONGJMP_FUNC)&the_jump_buf)(&the_jump_buf, argvalue);

Any implementation could support that convention, at the cost of one extra pointer within the jmp_buf object, and code produced using implementations that follow that convention could pass around and use pointers to jmp_buf objects interchangeably, without regard for whether they had the same internal representation for anything but the function pointer.