Re: [go-nuts] Is there a way to implement this C macro in Go?

2016-07-22 Thread Matt Harden
No, there's no way to do that in Go. There is no preprocessor nor any other way to obtain the original expression. You'll have to duplicate the expression as part of your format string. On Fri, Jul 22, 2016 at 6:57 AM Sam Whited wrote: > On Thu, Jul 21, 2016 at 7:09 PM, sque via golang-nuts > w

Re: [go-nuts] Is there a way to implement this C macro in Go?

2016-07-22 Thread Sam Whited
On Thu, Jul 21, 2016 at 7:09 PM, sque via golang-nuts wrote: > The "#x" is the really useful part that lets you print the original > expression. For example, if int a = 4 and int b = 10 This is not exactly the same, but %#v is probably what you want: https://godoc.org/fmt#hdr-Printing —Sam --

[go-nuts] Is there a way to implement this C macro in Go?

2016-07-22 Thread sque via golang-nuts
I've used this macro or some variant thereof in C/C++ for years: #define dump(x) printf("%s %d: %s = %d\n", __func__, __LINE__, #x, (int)(x)) The "#x" is the really useful part that lets you print the original expression. For example, if int a = 4 and int b = 10: dump(a + b); // Prints "a