[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 kan ikke være det Henrik mente oprindeligt...... Mon ikke han mener
nogenlunde det her:

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 );
}

NB! P eksisterer kun på stakken. Dette er meget upraktisk og bør nok
ikke gøres sådane, for kommer der flere funktionskald forsvinder den og
dermed muligheden for at frigive de n allokerede buffere.

Dette var bare min opfattelse, for her kommer der adressen på et array
af pointere til dynamiske FooBars ud af det.

M.v.h.
Søren H. Sørensen

Anders Melchiorsen wrote:
> 
> Henrik Brix Andersen <sslug@sslug> wrote:
> 
> > Mit spørgsmål går på hvordan jeg allokerer/tilgår n antal objekter
> > og returnerer et array af pointere til dem, se eksempel nedenfor...
> > det er altså syntaksen, jeg ikke lige kan greje...
> 
> Du skal vist bare fjerne en stjerne i forhold til dit oplæg,
> 
>         FooBar* foo = malloc(sizeof(foo) * n);
>         foo[2].bar = 42;
> 
> Anders.


 
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] *