Re: [go-nuts] Re: Passing a string

2017-11-06 Thread Ian Lance Taylor
On Mon, Nov 6, 2017 at 2:17 PM, Chun Zhang wrote: > > Can you please give some suggestion on how to properly handle this issue? > The C++ API cannot be modified. Use C.CString as described in the cgo docs at https://golang.org/cmd/cgo . Ian > On Monday, November 6, 2017 at 3:25:13 PM UTC-5, I

Re: [go-nuts] Re: Passing a string

2017-11-06 Thread Chun Zhang
Thanks Ian! Can you please give some suggestion on how to properly handle this issue? The C++ API cannot be modified. Sincerely, Chun On Monday, November 6, 2017 at 3:25:13 PM UTC-5, Ian Lance Taylor wrote: > > On Mon, Nov 6, 2017 at 10:59 AM, Chun Zhang > wrote: > > > > Sorry about the co

Re: [go-nuts] Re: Passing a string

2017-11-06 Thread Ian Lance Taylor
On Mon, Nov 6, 2017 at 10:59 AM, Chun Zhang wrote: > > Sorry about the confusion! My gocode set the value of the device and then > pass it to C++ code. > > Code goes like this: > > device := "eth1" // hardcoding this value works or retrieving it from Flag > as below > > flag.StringVar(&device, "D

Re: [go-nuts] Re: Passing a string

2017-11-06 Thread Chun Zhang
Hi, The configuration is the structure defined as type Configuration struct { IpToSend string PortToSend string Device string } The json file is { "IpToSend" :"", "PortToSend" :"2075", "Device" : "eth1" } The output of fmt.Sprintf("%T %#v", conf, con

Re: [go-nuts] Re: Passing a string

2017-11-06 Thread Tamás Gulácsi
Please, can you share the complete code? What is "Configuration"? What does `fmt.Sprintf("%T %#v", conf, conf)` print? I'm not sure about the swig-generated code, is your swig new enough? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubs

Re: [go-nuts] Re: Passing a string

2017-11-06 Thread Chun Zhang
Hi, Ian, Sorry about the confusion! My gocode set the value of the device and then pass it to C++ code. Code goes like this: device := "eth1" // hardcoding this value works or retrieving it from Flag as below flag.StringVar(&device, "Device", "eth1", "NIC to Listen") --- lines below

Re: [go-nuts] Re: Passing a string

2017-11-06 Thread Ian Lance Taylor
On Mon, Nov 6, 2017 at 10:29 AM, Chun Zhang wrote: > Thank you Ian!! That does make sense. > > Can you please elaborate why hardcoding device = "eth1" works? What is the > difference here? I'm sorry, I'm not sure I really understand the question. The pointer passing rules apply only when calling

Re: [go-nuts] Re: Passing a string

2017-11-06 Thread Chun Zhang
Thank you Ian!! That does make sense. Can you please elaborate why hardcoding device = "eth1" works? What is the difference here? Sincerely, Chun On Mon, Nov 6, 2017 at 1:19 PM, Ian Lance Taylor wrote: > On Mon, Nov 6, 2017 at 4:25 AM, Chun Zhang wrote: > > > > Thank you for the reply! > > >

Re: [go-nuts] Re: Passing a string

2017-11-06 Thread Ian Lance Taylor
On Mon, Nov 6, 2017 at 4:25 AM, Chun Zhang wrote: > > Thank you for the reply! > > The C libi.PI_init_global_config has the interface of > PI_init_global_config(int argc, char *argv[]); > so Swig converts it to PI_init_global_config(arg1 int, arg2 *string) > > The code was expecting to a *string.

[go-nuts] Re: Passing a string

2017-11-06 Thread Chun Zhang
Hi, Thank you for the reply! The C libi.PI_init_global_config has the interface of PI_init_global_config(int argc, char *argv[]); so Swig converts it to PI_init_global_config(arg1 int, arg2 *string) The code was expecting to a *string. Viper.GetString returns a string as far as I can see, is

[go-nuts] Re: Passing a string

2017-11-05 Thread Tamás Gulácsi
2017. november 6., hétfő 2:11:48 UTC+1 időpontban Chun Zhang a következőt írta: > > Hi, All, > > I am trying to read a configuration file using Viper, the config file is a > very simple json file with one line > { > "device" : "eth1" > } > > I use the following line to read it > > device := vi