B
bernd
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 and then pass the address of the inner structure to the
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.
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 ) ; }
}
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 and then pass the address of the inner structure to the
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.
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 ) ; }
}