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

Cannot evaluate sizeof arrays on compiletime #5802

Closed
zefciu opened this issue May 11, 2017 · 5 comments
Closed

Cannot evaluate sizeof arrays on compiletime #5802

zefciu opened this issue May 11, 2017 · 5 comments
Labels
VM see also `const` label

Comments

@zefciu
Copy link

zefciu commented May 11, 2017

The size of array is known on compile time, yet nim is unable to evaluate sizeof(SomeArrayType). This limits the ability to use computations on compile time. Found this trying to compute the md5 raindbow table on compile time.

Minimal example:

type                                                                            
  SomeType = array[0..10, string]                                               
                                                                                
const some_type_size = sizeof(SomeType)

Result:

const.nim(13, 30) Error: cannot evaluate 'sizeof(SomeType)'
@markus-oberhumer
Copy link
Contributor

Maybe somewhat releated, len(SomeArrayType) also does not compile.

var  v:  array[1..10, int]
type T = array[1..10, int]

var   a: int = v.sizeof
var   b: int = T.sizeof
const c: int = v.sizeof   # does not compile
const d: int = T.sizeof   # does not compile

var   e: int = v.len
var   f: int = T.len      # does not compile
const g: int = v.len
const h: int = T.len      # does not compile

@krux02
Copy link
Contributor

krux02 commented May 18, 2017

Well I have a pull request open to make sizeof work on all types at compile time very well here:
#5664
But my checks are failing, because the packed pragma is not correctly implemented:
#5824

@markus-oberhumer
Copy link
Contributor

It looks that len(SomeArrayType) has been implemented by #6032.

@mratsim
Copy link
Collaborator

mratsim commented Aug 3, 2018

Partially done by #8445

Primitive types will work, custom objects are pending #5664

@dom96 dom96 added the VM see also `const` label label Aug 3, 2018
@Araq
Copy link
Member

Araq commented Oct 15, 2018

This is now possible.

@Araq Araq closed this as completed Oct 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VM see also `const` label
Projects
None yet
Development

No branches or pull requests

6 participants