开发者

struct and arguments

I am trying to modularize a function that used to add values to multiple structures in one call. Now I want to do one value addition per call, but I am not sure how to 开发者_Go百科make a less specific argument reference.

func ( [?] *val )

{

}


If all structures start with the same "prefix", so you can reach the desired parts at the same offset, then you could make that prefix a struct of its own and pass a pointer to it -- a "poor man's version of inheritance".

If the desired portions are at different offsets in different structures you can't get away with passing just a pointer to the function (unless via an indirection layer, which can get even more complex) -- simplest may be to pass a pointer and offset, and use address arithmetic to reach the needed part. It's hard to give more specific advice without knowing how your various structures are laid out and what part(s) of them the function needs to reach!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜