On Wed, 19 Apr 2017 01:40:39 -0700 (PDT)
Frits van Bommel wrote:
> On Wednesday, April 19, 2017 at 9:10:16 AM UTC+2, hui zhang wrote:
> >
> > for 1) you mean
> >>
> >> char *CGetPath() {
> >> return getpath().c_str();
> >> }
> >
> >
> > this code will work ?
> >
>
> That depends on wheth
Please reply to the mailing list (use "reply all").
On Thu, Apr 20, 2017 at 4:39 AM, hui zhang wrote:
> Thank you , I believe most function will return string instead of string&
> I test return string function , as expected it return the wrong value
> as the string is invalid out of function
On Wednesday, April 19, 2017 at 9:10:16 AM UTC+2, hui zhang wrote:
>
> for 1) you mean
>>
>> char *CGetPath() {
>> return getpath().c_str();
>> }
>
>
> this code will work ?
>
That depends on whether getpath() returns a std::string or a (const)
std::string& (a (const) reference). It will
for 1) you mean
>
> char *CGetPath() {
> return getpath().c_str();
> }
this code will work ?
2017-04-19 14:43 GMT+08:00 Konstantin Khomoutov <
flatw...@users.sourceforge.net>:
> On Wed, 19 Apr 2017 14:23:09 +0800
> hui zhang wrote:
>
> > 1) getpath() return a temp string, its c_str
On Wed, 19 Apr 2017 14:23:09 +0800
hui zhang wrote:
> 1) getpath() return a temp string, its c_str() pointer will be
> free out of function. So I use malloc
I'm not completely sure you're correct. C++ does not implement garbage
collection and the object on which you have called c_str() con
1) getpath() return a temp string, its c_str() pointer will be free
out of function. So I use malloc
2) Assume we use the malloc way , are C.GoString() copying the pointer
memory ? for we need C.free() malloc memory.
2017-04-19 14:17 GMT+08:00 Konstantin Khomoutov <
flatw...@users.sour
On Tue, 18 Apr 2017 18:09:03 -0700 (PDT)
hui zhang wrote:
> > > c code
> > > string getstring() {...}
> > > go
> > > string gostr = (C.getstring())
> > Oh, and note that std::string is a fat object.
> >
> > So if getstring() really returns an instance of std::string,
> > and you need to
assume there is a c++ function string getpath()
you mean I should do this ?
>
char *CGetPath() {
> auto str=getpath;
> char *c = malloc(str.length()),
> strcpy(c,str.c_str());
> return c;
> }
p :=C.CGetPath()
> gostr := C.GoString()
>C.free(p)
在 2017年4月18日星期二 U
On Tue, 18 Apr 2017 02:25:07 -0700 (PDT)
hui zhang wrote:
> c code
> string getstring() {...}
>
> go
>
> string gostr = (C.getstring())
Oh, and note that std::string is a fat object.
So if getstring() really returns an instance of std::string,
and you need to actually extract its "raw b
On Tue, 18 Apr 2017 02:25:07 -0700 (PDT)
hui zhang wrote:
> c code
> string getstring() {...}
>
> go
>
> string gostr = (C.getstring())
https://github.com/golang/go/wiki/cgo#go-strings-and-c-strings ?
--
You received this message because you are subscribed to the Google Groups
"golang
c code
string getstring() {...}
go
string gostr = (C.getstring())
--
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
11 matches
Mail list logo