"Address boundary error" with struct
I am using gcc 4.3.3 on Ubuntu 9.04. The following code:
1 2 3 4 5 6 7 8 9
|
#include<stdio.h>
struct TEST {
int test;
};
int main(){
struct TEST *test;
test->test = 12;
printf("%d\n\n", test->test);
}
|
compiled good, but when I run it, I get the following message:
Job 1, './a' terminated by signal SIGSEGV (Address boundary error) |
Can anyone tell me what is wrong with my program? Thanks!
You haven't allocated an object, just a pointer. You need something like:
struct TEST *text = malloc( sizeof(struct TEST) );
and when you're done with it:
free( text );
Oh I see. Thank you very much.
Topic archived. No new replies allowed.