#Array of function pointers

1 messages · Page 1 of 1 (latest)

raven oracle
#
pub const OpcodeStep = fn (*OpcodeBuilder) void;
pub const test = struct { steps: []*OpcodeStep };

and then defining it:

        .steps = &[_]OpcodeStep{
            OpcodeBuilder.loadModrm,
        },

and i get
expected type '[1]*fn (*system.def.OpcodeBuilder) void', found '[1]fn (*system.def.OpcodeBuilder) void' this seems like a pretty easy fix but im not really sure how to appease this issue. any help would be appreciated!

teal zodiac
#

The type of steps should be []*const OpcodeBuilder, not []*OpcodeBuilder

raven oracle
#

i tried that first, and it gave me error: expected type '[1]*fn (*system.def.OpcodeBuilder) void', found '[1]fn (*system.def.OpcodeBuilder) void'

teal zodiac
#

isn't that the same error you sent above?

raven oracle
#

yes sorry i forgot i also modified it so &[_]*OpcodeStep which means it gave error: expected type '*fn (*system.def.OpcodeBuilder) void', found '*const fn (*system.def.OpcodeBuilder) void'

#

at this point i was unsure of how to proceed

teal zodiac
#
pub const OpcodeStep = fn (*OpcodeBuilder) void;
pub const test = struct { steps: []*const OpcodeStep };
        .steps = &[_]*const OpcodeStep{
            &OpcodeBuilder.loadModrm,
        },
raven oracle
#

oh ty the part i was missing was *const

#

i tried const*

#

and that is not ok

gloomy scarab
#

you need both, youre initializing it with a const array pointer

raven oracle
#

still doesn't work though 😅

gloomy scarab
#

[]const *const OpcodeStep

raven oracle
#

ty.

#

that got it

#

that is a bit of a huge hole in my knowledge though

#

is there a relevant part of the language spec?

limpid quest
raven oracle
#

ty. you know i read that and just internalized it as const*.