The real reason why C and by extension C++ suck is because they're land mines full of undefined behavior that have and...

The real reason why C and by extension C++ suck is because they're land mines full of undefined behavior that have and will keep catching even the most experienced programmers with their pants down, to illustrate, I bet none of you can explain how this function is unsafe.
void null_check(int *p, int s) {
int i = *p;
if(p == NULL)
return;
*p = s;
}

Attached: ron paul.gif (606x423, 467K)

Null check before i = *p

You should remove that first line. It doesn't do anything anyway.

>I compile trash with trash
Garbage in garbage out. Null check.

*p is a pointer to a pointer of the actual value of p, and you're checking if it's NULL when by definition it's undefined until assigned a value. Pic related because I'm just making shit up.

Attached: zachqwe1o4w01.jpg (317x380, 19K)

Attached: Screenshot_2018-09-26 g - dpt - Daily Programming Thread - Technology - 4chan.png (3328x740, 147K)

>dereferencing a pointer and then checking if it is null
>i isn't even used for anything

>I'd rather write assembly
This, but unironically. In fact just recently I've made macros for manually creating my own executables instead of being a cuck and relying on a compiler to do it for me. Mostly because I wanted to see if you can, and I was tired of my binaries including c library startup files when I'm using assembly and don't plan on using any c functions.

I'll admit the example is retarded but I'm talking about how it's perfectly valid according to the C standard for a compiler to completely remove lines 2 to 4. Here's a better example.
char *another_one(int size) {
if(size > size + 1)
return NULL;
char *str = malloc(size * sizeof(char));
return str;
}
Again, it's perfectly valid for a compiler to remove lines 2 and 3 because signed integer overflow is ub.

>manually
>manually
>manually
Maybe if a decent IDE was used instead of shitposting about >you only need muh text editor. Why are people so anal about using a proper tool?

how about making a check against INT_MAX instead?

Because we're not cucks like you.

>he needs an IDE to accommodate his crippled dev environment

> if(size > size + 1)
why don't you just use if(0)

overflow, it's not always 0
nobody writes code like this anyway so who cares

So ... don't write crappy code. The computer is just there to do what you tell it to. If you want to do silly things, then you're allowed. I don't think you have a valid point.

You are children; OP is right and everyone in the C++ committee admits it but you don't sperglords.

On the other hand, it's by design. If it changes, compatibility and performance breaks.

>full of undefined behavior

Not really, no. And they're languages for grownups who understand the underlying hardware, so it's usually pretty apparent when and why something would result in undefined behavior.

>it's usually pretty apparent when and why something would result in undefined behavior.
you are stupid; OP is right. There is noting "pretty apparent" about all undefined behaviors in C brainlet

thinking you know more than you do is the ultimate sign of stupidity

How the fuck isn't dereferencing a pointer before the null check an obvious case of UB and shitty code? You have to be clinically retarded to see that and think "yeah, this will work"

>You have to be clinically retarded to not notice two lines in C out of thousands other lines are out of order
A great sign of stupidity is to imply you are cleverer than you are child.

100% of the time before you use a pointer you should be checking if it's null. Not a difficult thing to remember.