ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I've spent quite some time on this issue, but I just can't see what I'm doing wrong. Take a look at this:
struct test {
int array[5];
int value;
};
struct test abc;
Well, guess what: abc.value and abc.array[5] are the same thing - they always have the same address. So if you write to abc.array[5] you automatically overwrite abc.value, and vice versa. But if the array and value aren't inside a structure, this doesn't happen. It's like the array inside the structure has 5 elements, while outside it has 6 elements (which is what I want ). So what is wrong here?
George
Last edited by george_mercury; 12-29-2004 at 02:41 PM.
So if you write to abc.array[5] you automatically overwrite abc.value, and vice versa. But if the array and value aren't inside a structure, this doesn't happen.
You're writing past the end of the array, like Proud said.
So, when you're array are "not inside a structure", and you write past the array, some other variable (or arguably worse, part of the stack) may, or may not get overwritten. If tou're "lucky" you get a "segmentation fault" runtime error...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.