Skip to main content
edited title
Link
BokkyPooBah
  • 40.4k
  • 14
  • 123
  • 193

Why Constant variable getsdo constant state variables get initialised every time?

deleted 34 characters in body
Source Link

I was working with constant variables in a contract

contract X{

uint constant b=now;var1=now;
uint var2=now;

function checkConstant() returns(uint,uint){
    return b;(var1,var2);
}} 

I was wondered each time I call checkConstant(..) , the return value returned was different. And if i declareof bvar1 aswas different but value of uint b=now;var2 each time I execute the function I getwas same value (which is expected).
So, I do not understand when I declare a variable as constant why it gets initialised each time a function is invokend, ideally it should get an initial value at time of contract deployment and maintain this value throughout life of contract.

I was working with constant variables in a contract

contract X{

uint constant b=now;

function checkConstant() returns(uint){
    return b;
}} 

I was wondered each time I call checkConstant(..) , the value returned was different. And if i declare b as uint b=now; each time I execute the function I get same value (which is expected).
So, I do not understand when I declare a variable as constant why it gets initialised each time a function is invokend, ideally it should get an initial value at time of contract deployment and maintain this value throughout life of contract.

I was working with constant variables in a contract

contract X{

uint constant var1=now;
uint var2=now;

function checkConstant() returns(uint,uint){
    return (var1,var2);
}} 

I was wondered each time I call checkConstant(..) , the return value of var1 was different but value of var2 was same.
So, I do not understand when I declare a variable as constant why it gets initialised each time a function is invokend, ideally it should get an initial value at time of contract deployment and maintain this value throughout life of contract.

Source Link

Why Constant variable gets initialised every time?

I was working with constant variables in a contract

contract X{

uint constant b=now;

function checkConstant() returns(uint){
    return b;
}} 

I was wondered each time I call checkConstant(..) , the value returned was different. And if i declare b as uint b=now; each time I execute the function I get same value (which is expected).
So, I do not understand when I declare a variable as constant why it gets initialised each time a function is invokend, ideally it should get an initial value at time of contract deployment and maintain this value throughout life of contract.