this post was submitted on 09 May 2024
458 points (92.4% liked)

Programmer Humor

32472 readers
601 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 39 points 6 months ago (22 children)

I didn't know why, but *++p bugs me

[–] [email protected] 29 points 6 months ago* (last edited 6 months ago) (11 children)

Perhaps *(p += 1) will be to your liking?

[–] [email protected] 15 points 6 months ago (3 children)

Much better... but can we make it *((void*)(p = p + 1))?

[–] [email protected] 3 points 6 months ago (1 children)

Why are you casting to void*? How is the compiler supposed to know the size of the data you are dereferencing?

[–] [email protected] 3 points 6 months ago* (last edited 6 months ago)

This would probably cause a compiler error....

But assuming it doesn't the context is p_ch = the bits above... the code declaring p_ch isn't shown but I'm guessing that the value here is actuality a pointer to a pointer so nothing illegal would be happening.

Lastly... C++ is really lacking in guarantees so you can assign a char to the first byte of an integer - C++ doesn't generally care what you do unless you go out of bounds.

The reason I'm casting to void* is just pure comedy.

load more comments (1 replies)
load more comments (8 replies)
load more comments (18 replies)