-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Allow to initialize constants in constructor #3356
Comments
While it might be tempting to re-use the |
Understood. What about |
This would be very useful. When a storage value is meant to be immutable, then a That said... I'm not sure how it could even be done in the current solidity constructor, since the values would need to be placed into the bytecode itself, like linking a library address. |
Would be important that the storage slot configuration isn't changed for storing this information, otherwise it could make difficult to use this with delegatecall. |
I strongly support this feature. It would greatly reduce the amount of assembly I have to write. As SLOAD cost climbs, placing constants in code will be increasingly important for gas savings. |
Closing this in favour of #3835 |
In some cases contracts have to be initialized with constant values: Contract A needs to know address of contract B. This address doesn't change anymore after deployment. Currently the easiest way to accomplish this is be passing the address of B to A as a constructor argument and save the address in a storage variable. This is very gas costly. It would be better to directly save the address in code. It would be beneficial if constants could be initialized in the constructor instead without using the contract storage at all:
If a constant is not initialized after the constructor is executed, the compiler should throw a compiler error.
The text was updated successfully, but these errors were encountered: