[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Array af pointere til strukturer



Det skrev jeg da også, at det var farligt :-)

Jeg overvejer om ikke det var smartere, når nu Henrik ikke kender n, at
lave en hægtet liste af FooBar-strukturer og så bare generere den
adressetabel ved behov. Jeg vil ikke skrive programmet lige nu, for jeg
skal ud af døren, men hermed er den kastet op i luften.

M.v.h.
Søren

donald axel wrote:
> 
> Pas på med at returnere pointer til local variable.
> 
> On Thu, 13 Mar 2003 05:11:21 +0100
> Søren H.Sørensen <sslug@sslug> wrote:
> 
> > typedef struct {
> >   ...
> > } FooBar;
> >
> > /* Vi antager at der er et antal af FooBars på n elementer */
> >
> > FooBar **get_foobars (void)
> > {
> >     FooBar *P[n]; /* Vores resulterende pointer-array */
> >     for( i=0 ; i<n ; i++ )
> >           P[i]=malloc( sizeof(FooBar) );
> >     return( &P );  /* <== nej, P[n] ophører med at eksistere efter return */
> > }
> 
> --
> d-axel.dk


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *