Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news-out.readnews.com!transit3.readnews.com!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: ctypes - python2.7.3 vs python3.2.3 Date: Fri, 7 Sep 2012 19:04:13 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 35 Message-ID: References: <18eb8025-7545-4d10-9e76-2e41deaadb69@googlegroups.com> <9a74$503e88dd$546bb230$30836@cache80.multikabel.net> NNTP-Posting-Host: panix2.panix.com X-Trace: reader1.panix.com 1347044653 13135 166.84.1.2 (7 Sep 2012 19:04:13 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Fri, 7 Sep 2012 19:04:13 +0000 (UTC) User-Agent: nn/6.7.3 Xref: csiph.com comp.lang.python:28704 In <9a74$503e88dd$546bb230$30836@cache80.multikabel.net> Jan Kuiken writes: > >> uint32_t myfunction (char ** _mydata) > >> { > >> char mydata[16]; > > > >> strcpy(mydata, "Hello Dude!"); > > > >> *_mydata = mydata; > > > >> return 0; > >> } > > > > mydata is an auto variable, which goes out of scope when myfunction() > > exits. *_mydata ends up pointing to garbage. > I'm not completely sure, but i think this can be solved by using: > static char mydata[16]; That will solve the immediate problem, however it makes myfunction() non-reentrant. > (Btw.: I don't know why you use char ** _mydata, i would use > char * _mydata, but then again, i'm not very familiar with > ctypes) He uses char **_mydata because he wants myfunction()'s caller to see the new value of _mydata, which it wouldn't if it were just char *_mydata. -- John Gordon A is for Amy, who fell down the stairs gordon@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"