954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pointer Lesson Problem

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. :)

chixm8_49
Light Poster
43 posts since Aug 2009
Reputation Points: 10
Solved Threads: 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.)

JeffGrigg
Posting Whiz in Training
218 posts since Aug 2011
Reputation Points: 192
Solved Threads: 28
 

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.

chixm8_49
Light Poster
43 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You