-
Notifications
You must be signed in to change notification settings - Fork 28
[Coding Guideline]: Do Not Depend on Function Pointer Identity #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
❌ Deploy Preview for scrc-coding-guidelines failed.
|
cleaned up some links and stuff
|
|
||
| - Comparing function pointers for equality (``fn1 == fn2``) | ||
| - Assuming a unique function address | ||
| - Using function pointers as identity keys (e.g., in maps, registries, matchers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can still use function pointers as keys, they just don't have a one-to-one relationship to function items, so you can't rely on a function item giving the same function pointer or different items giving different pointers. (ignoring #[no_mangle]). so e.g. you can have a HashSet<fn()> and it works just fine as long as you don't assume inserting any particular function item does anything other than guaranteeing calling one or more of the entries is equivalent to calling that function item.
resolved comments from reviewers
Coding guidelines based on #255