0

if you run the following (on eosio v1.8.4):

#include <eosio/eosio.hpp>
#include <eosio/asset.hpp>

namespace eosio {
    class UTL {
        public:
        static name code;
        static symbol sym;
    };  

    class [[eosio::contract("static")]] dapp : public contract {
        public:

        dapp(name receiver, name code, datastream<const char*> ds) 
            : eosio::contract(receiver, code, ds) {
            UTL::code = code;
            print("\nconstructor(I): code=", UTL::code);
            UTL::sym = symbol("XX", 2); 
            print("\nconstructor(II): code=", UTL::code);
        }   

        [[eosio::action]]
        void tst() {
            print("\ntst(): code=", UTL::code, ", sym=", UTL::sym);
        }   
    };  
}

you'll see that as soon as the second static variable gets set, the first one gets messed up. is this a problem with the EOS compiler, or am I doing something boneheaded?

Appendix I

thinking that perhaps having a single variable within the class would help I tried this, which fails in the same manner:

    class UTL {
        public:
        static struct {
            name code;
            symbol sym;
        } conf;
    };  

    class [[eosio::contract("static")]] dapp : public contract {
        public:

        dapp(name receiver, name code, datastream<const char*> ds) 
            : eosio::contract(receiver, code, ds) {
            UTL::conf = {.code = code, .sym = symbol("XX", 2)};
        }
        [[eosio::action]]
        void tst() {
            print("\ntst(): code=", UTL::conf.code, ", sym=", UTL::conf.sym);
        }   

1

the answer, as pointed out by larryk85 on github https://github.com/EOSIO/eosio.cdt/issues/751 is to properly initialise the static variables. duh!

    class UTL {
        public:
        static name code;
        static symbol sym;
    };  

    name UTL::code = name{};
    symbol UTL::sym = symbol{};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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