is this good to have pointers in programming languages such as golang,C or C++?

4.3k views Asked by At

Most of the modern programming compilers such as JAVA etc does not have the support of pointers. But in golang google introduce pointers again. So, i just want to understand how pointer effects a programming language? is there any kind of security thread because of pointers?

if this is because of security then why we have world's most secured system on LINUX and UNIX(both are build in C)

4

There are 4 answers

0
Jax On BEST ANSWER

Technically, all languages use pointers. When you create an instance of an object in Java or C# or Javascript and pass it to a method you are actually passing a pointer to the piece of memory that contains that object by which you will manipulate the data on that piece of memory. Imagine a language where you could not pass by reference. You wouldn't be able to do much, now would you? Whenever you pass by reference in any language, you're - in the most basic of terms - using glorified pointers.

What you probably mean, however, is "why expose pointers to people; they are so much more complicated", or something of that sort... And the answer is probably speed and tradition. Some of the fastest languages we have are C and C++... They've been around for a relatively long time. They are tried and true, and people know how to use them. Most software is based off of them in one way or another. Most operating systems are written in C or some variation thereof. Even other programming languages.

As for your Go example, we have already had a question on that..

2
Parag Surana On

Pointers makes call-by-reference easier, but are more vulnerable to breach, because through pointers we can directly access to the memory location, and thus can be a security concern.

Those problems can be defensively coded to prevent but that requires users to be knowledgeable and diligent.

2
user7358693 On

The 'modern' comparison of JAVA and C# to C++ is the worst thing a programmer can make. JAVA and C# are managed languages and that means that the memory is not managed by the programmer at all (that is the main function of pointers).C++ is an unmanaged language and that is why C++ is so much faster than any managed language. Almost every modern PC game you will ever see is made using C++ because it runs faster than any managed language.

0
user7358439 On

C/C++ pointer is operational. Example

void f(int* a) {
  a++

Direct operation is danger.

But, Golang pointer is not operational.

So, same name and same mean "pointer".

But, there are difference how to use.