Rockbox Development > Starting Development and Compiling

uninitialized elements

(1/1)

mschneider:
I've made a pointer to a structure like this:


--- Code: ---struct mystructure *p
--- End code ---

I access the structure various times but when I compile I get a warning that says "p" (I'm assuming that means the entire structure) is uninitialized in the function. What exactly does this mean?

saratoga:
Usually that means you're trying to dereference a pointer you haven't set to anything.  Have you actually assigned p a value before you try to use it?  On device, unlike on a PC, you can often dereference things that aren't actually valid pointers without crashing since theres no MMU watching what you're doing.

mschneider:
(Sorry, I'm horrible with pointers and I'm a little rusty on my coding), I did not think that a pointer to a structure needed a value. I thought you merely declared it as a pointer and then used it to pass things off to the structure. How would I set it to a value?

bluebrother:
well, as a pointer to a structure is still a pointer so it needs something to point to -- in that case it needs to point to a variable of that structure. Of course the pointer is initialized even if it points to some nonsense location or is set to NULL. You shouldn't forget to check against a NULL pointer before using it (in a function) of course.

You can understand it as a pointer doesn't have a value but a location it points to. If you haven't set the location its uninitialized.

mschneider:
Ok, that makes sense. thank you.

Navigation

[0] Message Index

Go to full version