C-Kurs/Bus Error/Musterlösung
Der Bus Error wurde bereits in der VL erwähnt. Hier ein Quellcodeauszug aus [1], der ihn erzeugt.
struct thing {
int an_int;
};
struct header {
short id;
char data[0];
};
struct header * maker( int size ) {
return (struct header *)malloc( sizeof( struct header ) + size );
}
int main( void ) {
struct header * a_headered_thing = maker( sizeof( struct thing ) );
struct thing * a_thing = (struct thing *)&(a_headered_thing->data[0]);
a_thing->an_int = 42; }