Go Down

Topic: Pointer safety and protection (Read 1 time) previous topic - next topic

TolpuddleSartre

Quote
I could to some degree understand the problem if it would happen in a multi-threaded environment where the pointer is referencing a shared resource, but this would again be a rookie mishap
...and would hopefully be trapped by the MMU

PaulS

Quote
To mee it sounds alot like you are trying to code your way out of a problem which is placed 20" in front of the screen
I had to check. In my case, the problem is more like 24" in front of the screen.

One of the things I hate about C# is the insistence that pointers don't exist, when everything is a pointer, and the fact that you can't implicitly compare a pointer (object) to null. You must explicitly use "!= null".

There are, posted regularly on this forum, attempts to return pointers to memory that goes out of scope when a function ends, and plenty of attempts to pretend that pointers and arrays are complete interchangeable.

It is good that OP is at least aware that some checking of pointers IS useful, even if the examples, so far, are not all that good.
The art of getting good answers lies in asking good questions.

arduino_new

this check (along with array-access-out-of-bound check and others) would require run-time check. and C/C++ is all about no-run-time-check-whatsoever in the name of efficiency. but it makes sense especially on microprocessors because you would not want to waste memory for these "useless" check routines.

but you can look into <unique_ptr> for safe pointer references

MarkT

Use references rather than pointers unless you need pointer arithmetic.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

sthudium

To mee it sounds alot like you are trying to code your way out of a problem which is placed 20" in front of the screen :P ;)
I agree, it appears I am worrying about something that is extremely unlikely to happen.

But I did learn a lot, and I appreciate everyone who helped me.

Thanks, again.
I study the use of cognitive dissonance and confirmation bias to manipulate gullible people.

Go Up