On Sunday, 6 March 2022 at 20:40:17 UTC Kurtis Rader wrote:
> On Sun, Mar 6, 2022 at 12:33 PM jlfo...@berkeley.edu <jlfo...@berkeley.edu> > wrote: > >> Thanks for the quick reply. Let's say I wanted to pass "fileinfo" from my >> program to another function. What would I say in function's argument list >> for fileinfo's type? From your reply I'm guessing I would give "fileinfo >> *io/fs.fileinfo" but I'm not sure. >> > > If you're defining the function you would use "os.FileInfo" as the > argument type (or a pointer to that type if that's more appropriate). > > If you use a pointer to interface, bear in mind that a *os.FileInfo (pointer to interface) is not the same as a *os.fileStat. *os.fileStat is a pointer to a concrete type. If you assign that to an interface variable, it's boxed in a <type,pointer> wrapper. If you then take a pointer to that, you have a pointer to the <type,pointer> wrapper. Because an interface value already contains a pointer, there are fewer cases where it makes sense to pass a pointer to an interface value. The common reasons for passing a pointer - avoiding copying large data structures, and being able to pass 'nil' - are already met by a plain interface value. The only reason I can think of for passing a pointer to an interface is if you need the receiver to be able to mutate the value at the place where it was originally stored. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b7902c28-ba42-4802-9e88-42681b90ef7en%40googlegroups.com.