bernd wrote:
Quote:
Hi folks,
>
the code below "runs" with the following message:
>
Before structure assignment
Bus Error(coredump)
>
What I am trying to do is to define an "outer" structure containing an
inner one
Ok
and then pass the address of the inner structure to the
Quote:
pointer within the outer structure pointing to it's inner structure
(so that I can read in data into the outer structure and being able to
read it immediately from the inner structure). But obviously I am
doing something wrong.
This is Quite confusing !
Quote:
>
Cheers
>
>
Bernd
>
#include <stdio.h>
>
main () {
>
int debug = 1 ;
>
typedef struct inner {
>
long var1 ;
char text[5] ;
>
} instruct ;
>
>
typedef struct outer {
>
long count ;
struct instruct *toinstruct ;
>
} outstruct ;
>
>
instruct *in ;
int in_size ;
in_size = sizeof( *in ) ;
>
in = malloc( in_size ) ;
>
outstruct *out ;
if ( debug == 1 ) { ( void ) fprintf(stderr, "Before structure
assignment\n" ) ; }
>
out->toinstruct = in ;
>
if ( debug == 1 ) { ( void ) fprintf(stderr, "After structure
assignment\n" ) ; }
>
int out_size ;
out_size = sizeof( *out ) ;
out = malloc( out_size ) ;
>
if ( debug == 1 ) { ( void ) fprintf(stderr, "Sizes: inner: %d -
outer: %d\n", in_size, out_size ) ; }
>
}
From - Wed
struct stackelement{
int etype;/*etype equals INT,FLOAT,STRING*/
/*depending on the type of the */
/*corresponding element */
union{
int iVal;
float fVal;
char pVal[ARRAYSIZE];
}element;
};
struct stack{
int top;
struct stackelement item[STACKSIZE]; /*Array Of Structures */
};
void pop( struct stack *p, struct stackelement *se )
{
if( p->top == -1 )
puts( "Underflow\n" );
else
{
if( se->etype == INT )
printf( "Deleted Integer is %d\n", p->item[(p->top)--].element.iVal );
else if( se->etype == FLOAT )
printf( "Deleted Float is %f\n" , p->item[(p->top)--].element.fVal );
else if( se->etype == STRING )
printf( "Deleted String is %s\n" , p->item[(p->top)--].element.pVal );
else
puts("Unknown Error");
}
return;
}
You are probably trying to do something similar.Its an unrelated code
segment but hope you can get an idea.