🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #36

Re: Return a string in C???

#36
From: Karl Heinz Buchegger
Date: Tue, 03 Jun 2003 14:39
40 lines
2341 bytes

chris wrote:
> 
> "Richard Heathfield" <dontmail@address.co.uk.invalid> wrote in message
> news:bbg354$k2n$3@hercules.btinternet.com...
> > chris wrote:
> >
> > <snip>
> > >
> > >
> > > you could have the function allocate the buffer and return the length:
> > >
> > > int StringFunction (char ** buffer) {
> > >     int bufferSize;
> > >     ...
> > >     *buffer = (char *)malloc(bufferSize);
> >
> > What does the cast buy you?
> >
> > And why use int, when malloc takes size_t?
> >
> > <snip>
> >
> > --
> > Richard Heathfield : binary@eton.powernet.co.uk
> > "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
> > C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
> > K&R answers, C books, etc: http://users.powernet.co.uk/eton
> 
> my compiler complains about casting a void * to a value without doing it
> explicitly,

Then you are not using a C compiler, but are using a C++ compiler.
In this case you should drop malloc altogether and use new instead.


-- 
Karl Heinz Buchegger
kbuchegg@gascad.at
Technical Details
Message-ID: <3EDCB30B.A94BFC7C@gascad.at>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!l1146p01.dipool.highway.telekom.AT!not-for-mail
References: <oVDAa.85219$Vi5.2444320@news1.calgary.shaw.ca> <b709e49a.0306020942.3b31389d@posting.google.com> <bbg354$k2n$3@hercules.btinternet.com> <3M0Da.83479$%e.4559628@twister.austin.rr.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1014db,726fa50532a809c2
X-Google-Attributes: gid1014db,public
X-Google-Thread: 114592,726fa50532a809c2
X-Google-Attributes: gid114592,public
X-Google-Thread: 10d4ba,726fa50532a809c2
X-Google-Attributes: gid10d4ba,public
X-Google-ArrivalTime: 2003-06-03 07:39:08 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!l1146p01.dipool.highway.telekom.AT!not-for-mail
From: Karl Heinz Buchegger <kbuchegg@gascad.at>
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c
Subject: Re: Return a string in C???
Date: Tue, 03 Jun 2003 16:39:07 +0200
Organization: GASCAD
Lines: 40
Message-ID: <3EDCB30B.A94BFC7C@gascad.at>
References: <oVDAa.85219$Vi5.2444320@news1.calgary.shaw.ca> <b709e49a.0306020942.3b31389d@posting.google.com> <bbg354$k2n$3@hercules.btinternet.com> <3M0Da.83479$%e.4559628@twister.austin.rr.com>
NNTP-Posting-Host: l1146p01.dipool.highway.telekom.at (62.46.207.33)
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: fu-berlin.de 1054651147 9989039 62.46.207.33 (16 [95537])
X-Mailer: Mozilla 4.7 [en] (WinNT; I)
X-Accept-Language: en