14

Getting the error "Storage location can only be given for array or struct types" in a setup function. The exact line is

uint memory _total = 0;

I'm confused by the error, because I'm not trying to use storage, I'm trying to use memory.

2 Answers 2

11

The term "storage location" is a bit misleading here, it refers to a more general concept about where data is stored, i.e. in storage or in memory. The error occurs because the "storage location" is only relevant for reference types like structs and arrays and uints are always passed by value, so you cannot hold a reference to a uint in memory or storage. If you want to do that, you have to create a struct data type that only contains a uint.

2

"For almost all types, you cannot specify where they should be stored"

"local variables of value type (i.e. neither array, nor struct nor mapping) are stored in the stack"

source: http://solidity.readthedocs.io/en/v0.4.24/frequently-asked-questions.html

So you can not set storage location for uint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.