Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Memory allocation in Structure to Structure

Reply
Thread Tools

Memory allocation in Structure to Structure

 
 
pra_ramli@rediffmail.com
Guest
Posts: n/a
 
      03-08-2006
Hi all,
While coding, I got struck up in memory allocation for structure to
structure..
For instance..I wrote the following pgm..

#include <iostream.h>
#include <stdlib.h>

typedef struct A
{
int b;
int c;
struct E {
int d;
int e;
} *E;
} A;

void main()
{
A* i = (A * ) calloc(1,sizeof(A);
}

I need to allocate memory for the internal structure E. Iam getting
errors whatever format I follow.. i tried the following..
A.E = (E * ) calloc(1,sizeof(E);
A.E = (A.E * ) calloc(1,sizeof(E);
and other combinations..

Can anybody help me to sort out this problem???

Cheers,
Nick

 
Reply With Quote
 
 
 
 
TB
Guest
Posts: n/a
 
      03-08-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) skrev:
> Hi all,
> While coding, I got struck up in memory allocation for structure to
> structure..
> For instance..I wrote the following pgm..
>
> #include <iostream.h>
> #include <stdlib.h>
>
> typedef struct A


Are you writing C or C++?

> {
> int b;
> int c;
> struct E {
> int d;
> int e;
> } *E;
> } A;
>


struct A {
struct E { };
E * f;
};

> void main()
> {
> A* i = (A * ) calloc(1,sizeof(A);


A * i = new A;
i.f = new A::E;

> }
>
> I need to allocate memory for the internal structure E. Iam getting
> errors whatever format I follow.. i tried the following..
> A.E = (E * ) calloc(1,sizeof(E);
> A.E = (A.E * ) calloc(1,sizeof(E);
> and other combinations..
>
> Can anybody help me to sort out this problem???


Make sure the code is at least syntactically correct before you post.

--
TB @ SWEDEN
 
Reply With Quote
 
 
 
 
pra_ramli@rediffmail.com
Guest
Posts: n/a
 
      03-09-2006
I modified to the code as following and now it is working
#include <iostream.h>
#include <stdlib.h>

typedef struct A
{
int b;
int c;
struct E {
int d;
int e;
} *F;
}A;
A b;
void main()
{


b.F = new A::E; //mem alloc using new for a Nested Struct
b.F = (A::E* ) calloc(1,sizeof(A)); //second way.c the declartion
of struct


}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
memory allocation for structure array jvax C Programming 4 11-24-2010 11:43 PM
static memory allocation versus dynamic memory allocation Ken C Programming 24 11-30-2006 12:37 AM
What is the difference between dynamic memory allocation,and stack allocation ? chris C++ 6 10-28-2005 05:27 AM
Memory Allocation for Structure / Class akshay4friend@yahoo.com C++ 2 02-16-2005 04:08 PM
Structure memory allocation Trying_Harder C Programming 4 09-16-2003 02:07 PM



Advertisments