I read many articles which published by anti-C programmers...
They said, "pointers are dangerous"
Do you have any comments about this?
I read many articles which published by anti-C programmers...
They said, "pointers are dangerous"
Do you have any comments about this?
They obviously don't understand the point behind pointers...
My stand is that if your Anti C you've along way to go
Pointers can be dangerous in the same way that a sharp tool can be dangerous: They provide the potential to do harm to yourself.
Typically, misuse of pointers include:
- Writing beyond the range of memory the pointer was intended to be used at (e.g. allocate 10 bytes, or point to a string of 10 characters and write to bytes 11 or more).
- Using pointers that don't point to valid memory by not setting the pointer (e.g calling malloc or taking an address of something).
- Not freeing memory which is no longer used.
- Using pointers that have actually been freed.
But just like a knife, chisel or axe, they also provide great tools that can do good work when used correctly.
The people who complain about pointers being dangerous are usually coming from languages that don't have pointers - so they don't understand pointers.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.