logoalt Hacker News

jasdfwasdtoday at 2:02 PM1 replyview on HN

> p = (char*)"";

yikes


Replies

lioeterstoday at 2:22 PM

I thought that was a typo or the forum software removed something, but no - it's a pointer to an empty string literal. If I understand how that works, this creates a null byte (in the read-only memory section of the compiled output?) and points to it. Before this line it checks if p is NULL.

I wonder what is the advantage of doing this? Maybe to make sure that p is an actual pointer, so later code can just make that assumption.

show 1 reply