Pointers

General FreeBASIC programming questions.
Nxx
Posts: 32
Joined: Dec 23, 2007 20:50

Pointers

Postby Nxx » Dec 23, 2007 20:55

I wonder why pointers introduced into the language? Pointers lead to memory leaks and buffer owerflows. Safety was one of the advantages of Basic over other languages.

Most flaws in C code are direct consequences of incorrect pointer usage. It makes C one of the most unsafe and buggy languages in the world.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Dec 23, 2007 21:02

Pointers allow for dynamic memory and better control over it... Pointers are very important. To be compatible with C and C++ libraries, we also need pointers.

Incorrect pointer usage will in fact cause memory leaks, but pointers are very powerful tools and are necessary for features such as Object Orientation, for example. NEW and DELETE also help make pointer usage easier.


Pointers are very much so a good thing. Even Java has pointers - It just will manage the reference count for you. The question becomes then, given all of the uses of pointers: Why *wouldn't* we allow pointers? I'd be upset, personally, if FreeBASIC limited me like that.

It makes C one of the most unsafe and buggy languages in the world.
Bad code in any language is bad. You are in fact correct - C really isn't all that safe. C++ was a lot safer, but could have still been improved. I believe FreeBASIC makes things about as safe as C++ does, or more :-)
Last edited by anonymous1337 on Jan 05, 2008 5:28, edited 2 times in total.
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Dec 23, 2007 21:04

Nobody is forcing you to use pointers but Visual Basic didn't have pointers and you could still produce memory leaks by not properly disposing of objects.

I myself rely heavily on pointers both to add speed and scalability to my applications. I would highly recommend learning how to use them.

-Vince
LukeL
Posts: 118
Joined: Mar 14, 2006 17:26

Postby LukeL » Dec 23, 2007 21:08

If you google the pros of pointers in high level programming you'll see they far outweigh the cons.
Especially memory leaks and buffer overflows which can be easily avoided by good programming practice.
Nxx
Posts: 32
Joined: Dec 23, 2007 20:50

Postby Nxx » Dec 23, 2007 21:14

vdecampo wrote:Nobody is forcing you to use pointers but Visual Basic didn't have pointers and you could still produce memory leaks by not properly disposing of objects.


VB has hidden pointers. It does not allow pointer arithmetic, but you indeed can produce a memory leak (although it would be rather difficult and needs special effort).

What I want to point out is that pointers concept is unnatural for Basic. It has other features that make pointer usage not necessary such as arguments' transfere oprions ByVal and ByRef etc. It pointers introduced they create complete mess with it and break even syntax compatibility with other Basic dialects.
Nxx
Posts: 32
Joined: Dec 23, 2007 20:50

Postby Nxx » Dec 23, 2007 21:18

LukeL wrote:If you google the pros of pointers in high level programming you'll see they far outweigh the cons.
Especially memory leaks and buffer overflows which can be easily avoided by good programming practice.

Still no large project that uses C language could avoid these flaws. MS Windows has dozens of buffer overflow bugs, just the same UNIX, Mozilla has numerous memory leaks etc. These flaws are inherent for C and especially because of pointer arithmetic.
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Dec 23, 2007 21:34

Nxx wrote:What I want to point out is that pointers concept is unnatural for Basic.


Which BASIC? BasicA, GWBASIC, PowerBASIC, FreeBASIC, PureBasic, QuickBASIC, DarkBASIC, Visual Basic, VB.NET, CDBasic, SXWIZ...

The list goes on and on. Some use pointers. Some don't. Find the one that works for you and use it. Some of us like pointers. Why should we be penalized because you don't know, or don't want to know how to use them?

-Vince
Last edited by vdecampo on Dec 23, 2007 21:35, edited 1 time in total.
DrV
Site Admin
Posts: 2116
Joined: May 27, 2005 18:39
Location: Midwestern USA
Contact:

Postby DrV » Dec 23, 2007 21:40

Pointers are a powerful tool, and as with any powerful tool, it's quite possible to do both great good and great harm. That does not make a powerful tool inherently bad. If you prefer to use a handsaw, feel free to do so, but don't deny those of us who know how to safely use a chainsaw that possibility.
Nxx
Posts: 32
Joined: Dec 23, 2007 20:50

Postby Nxx » Dec 23, 2007 21:51

vdecampo wrote:
Nxx wrote:What I want to point out is that pointers concept is unnatural for Basic.


Which BASIC? BasicA, GWBASIC, PowerBASIC, FreeBASIC, PureBasic, QuickBASIC, DarkBASIC, Visual Basic, VB.NET, CDBasic, SXWIZ...

The list goes on and on. Some use pointers. Some don't. Find the one that works for you and use it. Some of us like pointers. Why should we be penalized because you don't know, or don't want to know how to use them?

-Vince


Which of them except FreeBasic use pointers? None. Basic language has other tools that make pointers unnecessary.
Last edited by Nxx on Dec 23, 2007 22:03, edited 2 times in total.
Nxx
Posts: 32
Joined: Dec 23, 2007 20:50

Postby Nxx » Dec 23, 2007 22:02

DrV wrote:Pointers are a powerful tool, and as with any powerful tool, it's quite possible to do both great good and great harm. That does not make a powerful tool inherently bad. If you prefer to use a handsaw, feel free to do so, but don't deny those of us who know how to safely use a chainsaw that possibility.


If to compare, it would be pointers to correspond to handsaw. Why use handsaw when there is safe certified machine that would saw anything you want according a program without any risk to damage yourself? This "powerful tool" is too costly for developers and the industry overall. Companies spent billions to find bugs caused by incorrect pointer use. Security flaws in operating systems, browsers etc due to pointers cost even more.

Can you please specify what you need pointers for? What thing you cannot make without pointers? In fact any code that uses pointers can be rewritten with safe Basic-specific constructs such as arrays.
DrV
Site Admin
Posts: 2116
Joined: May 27, 2005 18:39
Location: Midwestern USA
Contact:

Postby DrV » Dec 23, 2007 22:10

There are plenty of external C libraries that require the use of pointers, and these uses cannot be replaced by any FB-only magical array. There is no way around this unless you don't want to use any C libraries or want to write wrappers for all of them.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Postby MichaelW » Dec 23, 2007 22:16

-lang idiotproof
Nxx
Posts: 32
Joined: Dec 23, 2007 20:50

Postby Nxx » Dec 23, 2007 22:18

DrV wrote:There are plenty of external C libraries that require the use of pointers, and these uses cannot be replaced by any FB-only magical array. There is no way around this unless you don't want to use any C libraries or want to write wrappers for all of them.


Visual Basic can use any API existing in the system regardless which language it is written in. I do not realize about which libraries do you speak. Possibly it is UNIX-specific ones?
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Postby maddogg6 » Dec 23, 2007 22:29

I'll be the first to agree that 'pointers' was something my brain had to struggle with understanding (already knowing some basic).

But...

Can anyone here afford the amount of time it would take to wrap all those libs' - are there enough people *here*, who, because they only understand basic, are capable to take any real amount of the load to do this (ie: distribute the burden) ? - most likely not.

What thing you cannot make without pointers?

the answer is obvious - if you don't like pointers - don't use them.
My take on it is: pointers just makes a lot of things easier to do with FB.

This seems to be turning into a PC vs Mac debate... ??


If to compare, it would be pointers to correspond to handsaw.
How about the 'car' analogy?
How many people die in a car each year, when; we can walk; ride horses/bicycles - but we don't. why? Because a car is much more convenient despite their obvious dangers to society.
But, yes, there are those who choose to wait for the bus, I pass by them all the time.
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Postby maddogg6 » Dec 23, 2007 22:32

I do not realize about which libraries do you speak. Possibly it is UNIX-specific ones?

http://www.freebasic.net/forum/viewtopic.php?t=788

*most* are cross platform

Return to “General”

Who is online

Users browsing this forum: No registered users and 3 guests