> How does the compiler know sizeof(T)? >
interesting question. About obtaining sizeof(T). The sizeof(T) is known from the call site calling the generic function, in particular from the type of variable that's passed to the generic function. What If generic function calls another generic function (possibly in different "module"? Now the T in callee is equal to T in caller, so sizeof is same, no need to do anything. (remember i use single parametric so there is no T1, T2 etc...) After obtaining sizeof(T), it needs to be passed to the function. I'm no call convention expert so In my experiment I've did the stupid simplest thing to make it work, Before a call to a generic function, I emitted runtime setter to store it, then in function i get it from runtime. there is race, sure but can be swept under the rug by putting it to thread specific place, maybe G(goroutine) . > If it's passed as an argument or saved together with the struct or > something in that regard, you end up with the "java approach", if you have > the compiler specializes the function per size, you end up with the "C++ > approach" (also, in either case, there is no need for the "only pointers > are allowed" kludge), from > If go goes the Java way but does it somehow differently. Something clever but very practical. I believe this is possible. Perhaps modify Golang's 2.0 calling convention, that EVERY function must get upon compilation one extra invisible-to programmer argument that is pointer that when said function is generic, points to sizeof(T) storage place . If you're calling to non-generic function it's just NULL, and it seems like a waste? but does it slow it down everything so much?? > http://research.swtch.com/generic > The most basic rule, for everyone arguing in favor of generics, is, that > they need to decide which tradeoff they make and how they justify it. That > blog post should be step 1 for everyone wanting to propose generics. > -- 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. For more options, visit https://groups.google.com/d/optout.