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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What kind of address? An illegal memory address is an address that your program is not permitted to access. Modern operating systems give processes virtual address spaces and map address onto physical memory. A program that tries to access unmapped memory will not be allowed to do so (this is something of a simplification, but basically accurate).
The only thing that I can think about right now that could lead into an illegal address, is when using pointers, for example:
Code:
/* test.c */
#include <stdio.h>
int main()
{
int someInt = 3; /* declares an integer */
int *somePoint; /* declares a pointer */
int *anotherPoint; /* declares yet another pointer */
somePoint = &someInt; /* here we assign the pointer to the address
of someInt */
printf("%d\n", *somePoint);
printf("%d\n", *anotherPoint); /* this is an illegal address */
return 0;
}
The line "printf("%d\n", *anotherPoint);" should be an illegal address because the pointer has not been initialized. Some compilers should compile it without telling any erros, some should say that the value was not initialized and the program would either crash during the execution or print wrong things...
Last edited by Mega Man X; 03-12-2005 at 09:08 PM.
Hello, On Windows there is an API named VirtualQuery, using which one
can find whether a memory region is legal or illegal, can anybody
tell me an API with the same functionality on Linux.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.