|
|
Log in / Subscribe / Register

C is not as simple as it seems

C is not as simple as it seems

Posted Sep 26, 2024 6:51 UTC (Thu) by LtWorf (subscriber, #124958)
In reply to: C is not as simple as it seems by NYKevin
Parent article: Linus and Dirk on succession, Rust, and more

What would be the use case for pointer arithmetic between things that are in 2 different memory allocations?


to post comments

Look up a pointer to get associated tag.

Posted Sep 26, 2024 7:55 UTC (Thu) by gmatht (subscriber, #58961) [Link]

If you have a pointer to some fixed data structure that you can't (or shouldn't) modify, you may want to attach a tag to a pointer and then look up that tag in a binary tree. For example, imagine you have a hashing algorithm for some very large const strings that will not be deallocated. Internal to the hashing algorithm, you may wish to look up the nice short pointer/integer in a binary tree to find a cached hash. In this case, the order on the pointers doesn't really matter so long as there is a well-defined order.

C is not as simple as it seems

Posted Sep 26, 2024 19:58 UTC (Thu) by NYKevin (subscriber, #129325) [Link]

I'm not saying all (or even most) of these things have actual use cases. I'm just saying that pointers have a lot of complicated rules that are often not taught correctly or at all. Students are told that pointers are integers, and they are not.

C is not as simple as it seems

Posted Sep 26, 2024 20:22 UTC (Thu) by intelfx (subscriber, #130118) [Link] (1 responses)

> What would be the use case for pointer arithmetic between things that are in 2 different memory allocations?

Memmove between overlapping regions?

C is not as simple as it seems

Posted Sep 26, 2024 20:23 UTC (Thu) by intelfx (subscriber, #130118) [Link]

Correction, _potentially_ overlapping regions.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds