5

I like C++, but it is seriously easy to do fucked up things:

class Test{
public:
Test(){};
};

Test test;
Test* test2 = nullptr;
Test& test3 = *test2;
Test* test4 = (Test*)0x12345;
Test& test5 = *test4;
Test* test6;
Test& test7 = *test6;

No warnings at all. I wonder if there is a flag for this kind of stupidity. Here's your sign...

Comments
  • 14
    I prefer that there are no hard rules against stupidity. I don’t like things telling me what perfectly valid things I can and can’t do.

    If the cost is being able to do stupid things, too, that’s fine by me.
  • 3
    @halfflat I edited my comment; I meant rules/errors, not warnings. Warnings are a good thing! They can also be annoying things. Especially when they’re wrong and refuse to go away. Grumble.
  • 1
    That's why every time I pass a pointer to a function, I do some NULL checking. If it's a NULL pointer, then I print an error telling me where it happened.
  • 0
    @halfflat No it isn't. Normally binary logical operators are of equal precedence. They are a class of operators, like (*, /, %) or (+, -), and left associativity is what decides the order. "and" takes precedence in many programming languages because in speech "and" usually takes precedence over "or", but this is subjective so it's worth a set of parentheses.
  • 0
    @halfflat Oh, I thought there's no precedence. Thanks for this.
  • 0
    @Bybit260 Gross I hate null checks. I do Null object pattern. I hate having a codebase riddled with null checks
  • 1
    @Bybit260 asserts are lovely!
  • 0
    It's this freedom that also allows you to do some pretty incredibly efficient things with the memory or the cpu.

    I prefer it over the handholding of Java for example, that wont even allow me to put a return statement if Theres code after it
  • 0
    @Hazarth Could you please give an example where per-spec incorrect code is more efficient than anything you can do with the STL?
  • 1
    @Lor-inc using unions or pointer casting you can shove integers into longs and add them together and then split them again into ints to achieve certain data parallelism, though to be honest that's pointless now with mmx n stuff

    You can also use a similar trick with chars and string comparisons, a sufficiently long string can be sectioned into long 64bit numbers and compared with another 8chars at a time

    Also now I just figured that you can probably interlace arrays in memory so they get cpu cached both at the sametime (if you need to access elements that are close to each other?) I have to test that though

    Dunno, I try a lot of ugly hacks in case something fun works, and I benchmarked the first two and managed to outperform even boost, though the usage is less generic and again mmx, sse and sse2 make these hacks usually obsolete but hey! At least I know I can do these in case Im working with a cpu without simd instructions right?
  • 0
    The flag is called "use Rust"
Add Comment