You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
from which it can be seen that as soon as the second initilisation occurs (UTL::sym), the value of the first one (UTL::code) gets messed up
this approach is very useful as it allows me to create static methods for things for which I don't really need to or want to instantiate an object. but the static methods need access to certain variables, which can easily be initialised during the contract constructor
This is not a problem with CDT. Your program is using undefined behavior, and as such is doing something weird. You have to explicitly initialize those fields.
#include<eosio/eosio.hpp>
#include<eosio/asset.hpp>usingnamespaceeosio;classUTL {
public:static name code;
static symbol sym;
};
// initialize the static fields
name UTL::code = name{};
symbol UTL::sym = symbol{};
class [[eosio::contract]] test : public contract {
public:test(name r, name c, datastream<constchar*> d) : contract(r,c,d) {
UTL::code = c;
print_f("code= %\n", UTL::code);
UTL::sym = symbol("XX", 2);
print_f("code= %, sym= %\n", UTL::code, UTL::sym);
}
[[eosio::action]]
voidtst() {
print_f("tst() : code= %, sym= %\n", UTL::code, UTL::sym);
}
};
Output of cleos push action eosio tst '[]' -p eosio without static initialization:
I've posted here as a question https://eosio.stackexchange.com/questions/5106/static-values-get-mangled, in case I'm just doing something badly but I think this is a bug with the compiler. I have the code below:
from which it can be seen that as soon as the second initilisation occurs (UTL::sym), the value of the first one (UTL::code) gets messed up
this approach is very useful as it allows me to create static methods for things for which I don't really need to or want to instantiate an object. but the static methods need access to certain variables, which can easily be initialised during the contract constructor
however, this fails. here's typical output:
from which it can be seen that the value of
code
becomes corruptI'm running on eosio v1.8.4. help?
The text was updated successfully, but these errors were encountered: