Skip to content
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

initial pass at function pointers #45

Merged
merged 4 commits into from
Jan 31, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion reference/src/representation/function-pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ In Rust, a function pointer type, is either `fn(Args...) -> Ret`,
A function pointer is the address of a function,
and has function pointer type.
The pointer is implicit in the `fn` type,
and `fn` types are implicitly `'static`.
and they have no lifetime of their own;
therefore, function pointers are assumed to point to
a block of code with static lifetime.
This is not necessarily always true,
since, for example, you can unload a dynamic library.
Therefore, this is _only_ a safety invariant,
not a validity invariant;
as long as one doesn't call a function pointer which points to freed memory,
it is not undefined behavior.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just say something like: "Function pointers have no lifetime. They must point to an allocated block of code when being called."

The rest of this belongs to #72, doesn't it?



In C, a function pointer type is `Ret (*)(Args...)`, or `Ret ABI (*)(Args...)`,
and values of function pointer type are either a null pointer value,
Expand Down