Originally Posted by
errigour
I am trying to be very careful with pointing to memory and I was hoping someone can
save me the trouble of trying to point to memory without knowing about what I am
doing. My question is how do I? I might already know so you can just reply with you
got it if I am right. If I am wrong could you show me an example of pointing to a
specified memory location.
You're definitely not right. I think you need to do a lot more studying and practice before you actually try to do what you're after here.
I want to make a program that gives me a summery of my
my hard drive and I need a pointer to point to 0x0 and I want to make the pointer
increment what it's pointing to until the last memory location on my hardrive.
Pointers point to places in memory, your hard drive is not memory. C allows you to work with the file system on your hard drive, but the language itself doesn't allow raw access to your hard drive. You can not just start at address 0 on your hard drive and shlep through byte by byte, without some serious, hard core, low level code. Either super low-level driver stuff and/or some crazy assembly code would probably be necessary. I don't really know much about what it would involve, but plain old C won't really handle it. I couldn't even tell you where to start looking for this.
Also if you answer this could you show me a constant character method of pointing to
the information? If there is one.
Not totally sure what you mean here. Perhaps you mean a pointer to const data, i.e. you can "read" the values but can't "write" them? It's not complicated, lots of library functions like strlen do it:
Code:
char a;
char b;
const char *p = &a; // here, I can make p point to any address, but I can never modify the contents it's pointing to
*p = 'a'; // the compiler wont allow this, because you declared p to point to a const char, so it can't be changed
p = b; // I can change what p points to, but again, I can't store anything there
The code below is what I hope will do it. I would love to here what people have to
say about this post.
Code:
char *char_ptr;
char_ptr=0x0;
I believe that this is absolutely completely unsafe to practice.
const char int_ptr;
&int_ptr=0x0;
Yep, that's totally unsafe, and some of it plain old won't compile. you set char_ptr to point to the address 0x0, which is basically NULL (I won't get into exactly what NULL is or isn't, the jury is still out on that one).
The code you believe is unsafe won't even work. First, you declare a const char called int_ptr (bad name, but whatever). That means it contains a single byte, one char, and it can't change. If it's a global var, it's initialized to 0 and stuck there. If it's a stack variable, it's initialized to garbage and wont change. That's pretty useless either way. Also, the last line is impossible. The & (address of) operator does not produce a modifiable value. It would be like trying to "relocate" int_ptr, which doesn't make sense, especially since you're trying to relocate it to NULL.