Here is my sample contract code, but I got an error,

TypeError: Storage location can only be given for array or struct types.

I just wannted to define some element of a structure in a function,

contract MyContract {
   PC[] public pcs;
   structure PC {
      string name,
      uint time

   function checkTime(uint _pcid) public {
      uint memory a = pcs[_pcid];
      string memory b = pcs[_pcid];
      //do something with a and b...

What am I doing wrong? do I have to define storage instead of memory??

1 Answer 1


The syntax is not correct. The base type doesn't have the storage location. Its reserved for array or struct.

So you either do

PC memory structure = pcs[_pcid];


uint a = pcs[_pcid].time;
string memory b = pcs[_pcid].name;
  • Thanks, But when I try to compile (0.4.21), I've got, " Warning: Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning." for a string variable. why there is no warning message for uint type?
    – Kronos
    Apr 13, 2018 at 14:51
  • oh, sorry yes. memory has to be used for string type since its dynamically resolved. For other base type is not necessary
    – qbsp
    Apr 13, 2018 at 14:59

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.