0

Hello. ^^
I would like to know why most pointers of most languages restricted to pointing at a single type object. Is it because for readability purposes? Memory address? Or another reason?

Thanks. :)

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by chixm8_49
0

It's a pragmatic issue, really: You can't do much with a pointer unless you know something about the structure of what it points to. And if you get it wrong, you typically corrupt your data and you can very easily crash the program.

PASCAL allows you to overlay pointers using the "union" construct -- having one pointer point to several different kinds of things.

C/C++ support "void pointers" with the "void *" syntax. This means "this is a pointer to something, but I'm not telling you anything about what it points to." C/C++ gives you a lots of freedom to arbitrarily change one pointer type to another, to move pointers around, to reinterpret them, and to corrupt memory and crash the program. ;->

Java is unusually strict in its handling of pointers. You can't corrupt memory or crash the program in Java. (...except in the sense that throwing exceptions can terminate a program -- in a controlled and well defined manner.)

0

Sorry for the late response. ^^;;
Anyway, thanks for the reply.

C/C++'s pointers are strong but I guess, we really need to be extra careful when using them.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.