Should C++ have better pointers?

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 5219 Views - Last Post: 30 September 2014 - 07:19 PM

#16 infernorthor  Icon User is offline

  • D.I.C Lover

Reputation: 276
  • View blog
  • Posts: 1,298
  • Joined: 07-February 14

Re: Should C++ have better pointers?

Posted 13 May 2014 - 06:04 PM

I think some of you missed the point I was trying to make. I didn't come up with this based on some particular need for it, but curious to simple things that could benefit the language on compile side as to not interfere with old code.

My point of perhaps better pointers or mainly adding type modifiers, is to query what safety could be added to the language.

Some of what you said is the same as arguing that word 'const' is pointless you just need to write code carefully. And you don't benefit from it if you don't use it. And yet people use it, and I'm sure it has kept many from doing bad mistakes.
Was This Post Helpful? 0
  • +
  • -

#17 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 678
  • View blog
  • Posts: 2,337
  • Joined: 31-December 10

Re: Should C++ have better pointers?

Posted 17 May 2014 - 01:12 PM

The keyword const is far from pointless and I don't think I've heard of anyone who knew what they were talking about, argue that const is pointless.
Was This Post Helpful? 0
  • +
  • -

#18 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 678
  • View blog
  • Posts: 2,337
  • Joined: 31-December 10

Re: Should C++ have better pointers?

Posted 17 May 2014 - 01:19 PM

View PostSP135, on 13 May 2014 - 06:33 AM, said:

The only thing i hate is that the "member of pointer" operator is different than "member of object" operator. Using '->' instead '.' has no advantages really.

The '->' operator is actually two operators in one so comparing it to the regular dot '.' operator is like comparing apples and oranges. The '->' operator is actually this: (*ptrToObj).member, so you tell me, which would you prefer to keep writing:
string *s1, *s2;

(*s1).size();

s2->size();


Was This Post Helpful? 0
  • +
  • -

#19 jimblumberg  Icon User is offline

  • member icon


Reputation: 4140
  • View blog
  • Posts: 12,883
  • Joined: 25-December 09

Re: Should C++ have better pointers?

Posted 17 May 2014 - 02:56 PM

And don't forget the parentheses are mandatory, because of operator precedence, that's probably one reason to use the operator-> instead of the dot operator when dealing with pointers.


Jim
Was This Post Helpful? 0
  • +
  • -

#20 infernorthor  Icon User is offline

  • D.I.C Lover

Reputation: 276
  • View blog
  • Posts: 1,298
  • Joined: 07-February 14

Re: Should C++ have better pointers?

Posted 17 May 2014 - 06:43 PM

I'm sure a compiler could handle that conversion. Though it would be more work is the only thing, but C++ already has to check the type for other reasons, so shouldn't be much more. Back when C was designed more work was more of a problem with slower computers. An object is like (*this).member which is *(this+offset). So such conversion can be done. A pointer would never have members only it's dereferenced value would. I think the distinction is good though, for readability.
Maybe a single symbol would've been faster to write though, like ptr@member.
Was This Post Helpful? 0
  • +
  • -

#21 SP135  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-May 14

Re: Should C++ have better pointers?

Posted 19 May 2014 - 01:01 AM

View Postinfernorthor, on 17 May 2014 - 06:43 PM, said:

I'm sure a compiler could handle that conversion.

Ofcourse it can.
Was This Post Helpful? 0
  • +
  • -

#22 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 678
  • View blog
  • Posts: 2,337
  • Joined: 31-December 10

Re: Should C++ have better pointers?

Posted 20 May 2014 - 08:50 AM

View Postinfernorthor, on 17 May 2014 - 09:43 PM, said:

I'm sure a compiler could handle that conversion. Though it would be more work is the only thing, but C++ already has to check the type for other reasons, so shouldn't be much more. Back when C was designed more work was more of a problem with slower computers. An object is like (*this).member which is *(this+offset). So such conversion can be done. A pointer would never have members only it's dereferenced value would. I think the distinction is good though, for readability.
Maybe a single symbol would've been faster to write though, like ptr@member.

What you're talking about is implementation dependent. Granted, most compilers might implement classes in that way, but they're not required to do so. I think you should read up on the history of C++ so as to grasp a better understanding of why things are the way they are, and also, why it's extremely difficult even to make seemingly minor changes as you are proposing.
Was This Post Helpful? 0
  • +
  • -

#23 Richard_Grant  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 2
  • Joined: 25-September 14

Re: Should C++ have better pointers?

Posted 25 September 2014 - 12:27 PM

No, The pointers are perfectly fine.
Was This Post Helpful? 0
  • +
  • -

#24 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 678
  • View blog
  • Posts: 2,337
  • Joined: 31-December 10

Re: Should C++ have better pointers?

Posted 26 September 2014 - 05:58 AM

View Postinfernorthor, on 13 May 2014 - 09:04 PM, said:

Some of what you said is the same as arguing that word 'const' is pointless you just need to write code carefully. And you don't benefit from it if you don't use it. And yet people use it, and I'm sure it has kept many from doing bad mistakes.

Using the const keyword isn't just about keeping you from making mistakes. For example, passing a const reference as a function argument. By doing so, the compiler may be able to perform some optimizations whereas if you just had a regular variable it might not be able to. I suggest you read the "Design and Evolution of C++." And maybe even the Annotated Reference Manual or ARM for short.
Was This Post Helpful? 0
  • +
  • -

#25 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1086
  • View blog
  • Posts: 4,563
  • Joined: 09-June 09

Re: Should C++ have better pointers?

Posted 30 September 2014 - 07:19 PM

There's a reason that higher level languages exists.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2