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
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
--
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