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

Reserve sizeof keyword #9333

Closed
brson opened this issue Sep 19, 2013 · 3 comments · Fixed by #9389
Closed

Reserve sizeof keyword #9333

brson opened this issue Sep 19, 2013 · 3 comments · Fixed by #9389
Labels
A-grammar Area: The grammar of Rust E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@brson
Copy link
Contributor

brson commented Sep 19, 2013

Nominating.

(Clarification from Felix: We already have sys::size_of::<T>(), but you cannot use that in const-expressions. Thus the proposal that we grab sizeof as a keyword, so that we can incorporate it into an extension of the current set of const-expressions. At least, that's how Felix understands the situation.)

@nikomatsakis
Copy link
Contributor

Might as well be the same as C (i.e., sizeof). Also, let's
reserve offsetof while we're at it.

@thestinger
Copy link
Contributor

C also has alignof (and alignas, but that would be an attribute) now. The offsetof implementation is just a macro in C and could likely be one in Rust too.

@nikomatsakis
Copy link
Contributor

On Fri, Sep 20, 2013 at 02:41:21AM -0700, Daniel Micay wrote:

C also has alignof (and alignas, but that would be an attribute)
now.

Yes.

The offsetof implementation is just a macro in C and could likely
be one in Rust too.

Hmm, I considered that. I was thinking that it could not be a macro if
we wanted it to appear in constant expressions. But I guess that's not
true, since all the macro does is something like

&((T*)NULL)->f

which I believe is legal in our constant expressions -- or at least
might as well be legal in any world that permits sizeof in a
constant expression.

In that case, we don't need to reserve offsetof, except that it would
mean you write sizeof(T) (or whatever) but offsetof!(T,f). I guess
that's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-grammar Area: The grammar of Rust E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants