Pointer Hell

Started by
11 comments, last by Witchcraven 21 years ago
Ok, when I used that code I got an odd error:
request for member `sections'' in something not a structure or union.

So I changed ManifestSection to:

void ManifestSection(struct Section **s, unsigned int x, unsigned int y)
{
struct Section *temp=(struct Section *)malloc(sizeof(struct Section));
temp->grid=(unsigned long int **)malloc(PTRSIZE*10000);
temp->x=x;
temp->y=y;
*s=temp;
}

all things seem to be working without seg faults, but is there a better way to do this without a temporary variable. My attempts at typecasting seemed to fail. Thanks in advance.
--------------------------I present for tribute this haiku:Inane Ravings OfThe Haunting JubilationA Mad Engineer©Copyright 2005 ExtrariusAll Rights Reserved
Advertisement
Nm. I think I must be dislexic or something
This avoids the temporary variable,

void ManifestSection( struct Section **s, unsigned int x, unsigned int y ){    assert( s );    *s = (struct Section*) malloc( sizeof(**s) );    (*s)->grid = (unsigned long int**) malloc( PTRSIZE * 10000 );    (*s)->x = x;    (*s)->y = y;} 

This topic is closed to new replies.

Advertisement