473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

If we could do it all over again : rethinking pointer syntax

C++ is always evolving. Within C++, there tend to be two communities.
There is the community pushing for performance features, getting ever
closer to the metal, and then, there is the applications community.

The applications community would, in general, prefer C++ to become more
high level - adding things like garbage collectors, improved pointer
safety, in short, to be a language useful for building applications
that now go to the Java and C# and even the D crowds.

The systems community does not want C++ to not be any of that. They
want C++ to be good at writing Java's and C#'s and D's. They want C++
to stick to its roots as a good systems language, where we can build
libraries to build applications with, if we choose. To them, a 64k
application is still a worthy goal for the sake of fitting into 64k.

The thought has occurred to me that the systems crowd will ultimately
lose. More people want applications and generally speaking, trading a
bit of performance to gain safety or ease of use has produced good
results. But that leaves us systems people in need of a C/C++ for
systems.

So, with the idea in mind that C++ may well fork, or, some other
systems language will be needed to fill a hacker void, then, one must
attend to the subject of pointers. Applications people often loath
pointers - indeed, other applications languages simply do not have
them. On the other hand, systems people love pointers. So, any future
systems language will have to have pointers.

And that really begs the question, can the pointer be improved? For
me, the *dereference or element->node syntax is troublesome becuase it
complicates the use of templates. You either need to have special
accessors, wrap things up in references, and so on. What if, the
*dereference was actually implied with a pointer, such that:

char *test = "foo";

printf( "%c", test );

would yield "f" as its output.

iterating a pointer could still work by array index. The relationship

test[0] == test

would always work for pointer types, assuming test was in the same
spot.

I've thought about the idea of always making everything a pointer, as
is the case in Java or C#, but, that has its own problems.

Thoughts? I already know I'm crazy.

Dec 18 '06 #1
6 1255

stork wrote:
C++ is always evolving. Within C++, there tend to be two communities.
There is the community pushing for performance features, getting ever
closer to the metal, and then, there is the applications community.

The applications community would, in general, prefer C++ to become more
high level - adding things like garbage collectors, improved pointer
safety, in short, to be a language useful for building applications
that now go to the Java and C# and even the D crowds.

The systems community does not want C++ to not be any of that. They
want C++ to be good at writing Java's and C#'s and D's. They want C++
to stick to its roots as a good systems language, where we can build
libraries to build applications with, if we choose. To them, a 64k
application is still a worthy goal for the sake of fitting into 64k.

The thought has occurred to me that the systems crowd will ultimately
lose. More people want applications and generally speaking, trading a
bit of performance to gain safety or ease of use has produced good
results. But that leaves us systems people in need of a C/C++ for
systems.

So, with the idea in mind that C++ may well fork, or, some other
systems language will be needed to fill a hacker void, then, one must
attend to the subject of pointers. Applications people often loath
pointers - indeed, other applications languages simply do not have
them. On the other hand, systems people love pointers. So, any future
systems language will have to have pointers.

And that really begs the question, can the pointer be improved? For
me, the *dereference or element->node syntax is troublesome becuase it
complicates the use of templates. You either need to have special
accessors, wrap things up in references, and so on. What if, the
*dereference was actually implied with a pointer, such that:

char *test = "foo";

printf( "%c", test );

would yield "f" as its output.

iterating a pointer could still work by array index. The relationship

test[0] == test

would always work for pointer types, assuming test was in the same
spot.

I've thought about the idea of always making everything a pointer, as
is the case in Java or C#, but, that has its own problems.

Thoughts? I already know I'm crazy.
I don't get it. If so many applications programmers can't wrap their
heads around C++, or simply don't think it's the right tool for the
job, why don't they simply switch to another language? The idea that
C++ will 'become something more high level' is somewhat ludicrous when
there are already other 'more high level' languages out there.

Dec 18 '06 #2

jjds...@yahoo.com wrote:
I don't get it. If so many applications programmers can't wrap their
heads around C++, or simply don't think it's the right tool for the
job, why don't they simply switch to another language?
Because this is all meaningless conjecture.
The idea that
C++ will 'become something more high level' is somewhat ludicrous when
there are already other 'more high level' languages out there.
On the other hand, there has been a "fork". Interestingly it was
created so that application programmers *could* have pointers and all
the "bad" things that C++ has. I can't imagine a lot of systems
programming takes place in .net.

Dec 18 '06 #3
stork wrote:
C++ is always evolving. Within C++, there tend to be two communities.
There is the community pushing for performance features, getting ever
closer to the metal, and then, there is the applications community.

The applications community would, in general, prefer C++ to become more
high level - adding things like garbage collectors, improved pointer
safety, in short, to be a language useful for building applications
that now go to the Java and C# and even the D crowds.
[...]
>
So, with the idea in mind that C++ may well fork, or, some other
systems language will be needed to fill a hacker void, then, one must
attend to the subject of pointers. Applications people often loath
pointers - indeed, other applications languages simply do not have
them. On the other hand, systems people love pointers. So, any future
systems language will have to have pointers.

And that really begs the question, can the pointer be improved? For
me, the *dereference or element->node syntax is troublesome becuase it
complicates the use of templates. You either need to have special
accessors, wrap things up in references, and so on.
[...]

C++ could use better pointer abstraction so that using smart pointers
would be less awkward.

Some sort of way of overriding the casting operator for (void *) and
(char *) so you could use smart pointers where regular pointers were
used. I tried this once but ran into various kinds of problems, some
of which may have been caused by a non compliant compiler.

Also some way of forbiding assignment of the raw pointer value to void*
or char* to prevent uncontrolled usage of that value.

And some kind of attribute on methods so the compiler could optimize
the results of methods that were idempotent as long as no methods that
modified the object were called. You'd want this to make up for not
being able to optimize by explicitly assigning the raw pointer value
to a variable.

This would go a long way to making smart pointers look a lot like
regular pointers.

There's also some issues with new and delete being in the wrong place
but I've mentioned that before.
--
Joe Seigh

When you get lemons, you make lemonade.
When you get hardware, you make software.
Dec 18 '06 #4
Stork replied to:
There's also some issues with new and delete being in the wrong place
but I've mentioned that before.
Actually, for my benefit, can you either expound or provide a link?

Dec 18 '06 #5
stork wrote:
Stork replied to:

>>There's also some issues with new and delete being in the wrong place
but I've mentioned that before.


Actually, for my benefit, can you either expound or provide a link?
Usually you want the smart pointer to control allocation and decallocation
since that's what smart pointers do, manage memory. The way it's done
now is problematic. You have problems with raw objects being assigned to
two separate smart pointers when it should have been only one and then
just smart pointer copying after that. Or you have to create a derived class
to override new and delete for things like intrusive reference counting.
Except the derived class can't be used transparantly as the class it was
based on. Making new and delete virtual would work somewhat but it would
be better to make them virtual methods for the smart pointers so that
different allocation policies could interoperate, e.g. using objects that
come from different alocation pools but are otherwise identical.

--
Joe Seigh

When you get lemons, you make lemonade.
When you get hardware, you make software.
Dec 18 '06 #6

stork wrote:
C++ is always evolving. Within C++, there tend to be two communities.
There is the community pushing for performance features, getting ever
closer to the metal, and then, there is the applications community.

The applications community would, in general, prefer C++ to become more
high level - adding things like garbage collectors, improved pointer
safety,
You can do all of that in C++. It's just not built in.
in short, to be a language useful for building applications
that now go to the Java and C# and even the D crowds.
But C++ is already useful for building those sorts of applications. I
forever find myself returning to it when a higher-level utopia has lost
its lustre. In fact, I find that a great many of the applications I
depend on most are written in C++, even though modern higher-level
alternatives were available; and I don't think the choice was generally
made from habit alone.
The systems community does not want C++ to not be any of that. They
want C++ to be good at writing Java's and C#'s and D's. They want C++
to stick to its roots as a good systems language, where we can build
libraries to build applications with, if we choose. To them, a 64k
application is still a worthy goal for the sake of fitting into 64k.

The thought has occurred to me that the systems crowd will ultimately
lose.
Why? Are you assuming that the language itself will be changed in a way
that the "systems crowd" won't want to use it any more? I doubt that
will happen any time soon, if ever, but even if it did, I think
compilers for the old C++ would remain available and used -- see
Fortran.
More people want applications and generally speaking, trading a
bit of performance to gain safety or ease of use has produced good
results. But that leaves us systems people in need of a C/C++ for
systems.

So, with the idea in mind that C++ may well fork, or, some other
systems language will be needed to fill a hacker void, then, one must
attend to the subject of pointers. Applications people often loath
pointers -
Silly people.
indeed, other applications languages simply do not have
them. On the other hand, systems people love pointers.
Well -- I wouldn't go quite *that* far.
So, any future
systems language will have to have pointers.

And that really begs the question, can the pointer be improved?
For some things, yes. And so the reference was invented.
For
me, the *dereference or element->node syntax is troublesome becuase it
complicates the use of templates. You either need to have special
accessors, wrap things up in references, and so on. What if, the
*dereference was actually implied with a pointer, such that:
Because then you couldn't do direct pointer manipulation any more -- or
am I not getting what you're saying?

The current syntax has the advantage that you always know when you're
working with a pointer, and if you don't, the compiler will generally
hit you over the head. A reference doesn't have that syntax, because it
doesn't need it; it really is a "safe pointer".

And speaking of references, how does your proposal improve on or
complement them?
>
char *test = "foo";

printf( "%c", test );

would yield "f" as its output.

iterating a pointer could still work by array index. The relationship

test[0] == test

would always work for pointer types, assuming test was in the same
spot.
This smells like syntactic quicksand to me.
I've thought about the idea of always making everything a pointer, as
is the case in Java or C#, but, that has its own problems.
It certainly does. That *would* all but destroy C++'s usefulness as a
low-level language.

--mpa

Dec 18 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: James.D | last post by:
Hi, I met such a problem: //--------------------- // .h class CA { protected: void (CA::*)m_pfn(); public:
4
by: Jerry Krinock | last post by:
I've written the following demo to help me understand a problem I'm having in a larger program. The "main" function constructs a Foo object, and then later "reconstructs" it by calling the...
10
by: Matt Silberstein | last post by:
I am trying to make a page that will be 800px wide. That is, I have an 800px image. I want the content of the page centered. I can do that fine. On the top, I want an image logo with a text menu...
3
by: Thomas Matthews | last post by:
Hi, At my work, we have a need for a pointer to a pointer to a function returning void and having void parameters. Since this is an embedded system, we have to assign the variable with a...
13
by: Arsalan | last post by:
Is there any advantage in C# over VB.NET ? Or the difference is only syntax ? Can anything done in C# which cannot be done in VB.NET?
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
10
by: ravi | last post by:
Hi, i am a c++ programmer, now i want to learn programming in c also. so can anybody explain me the difference b/w call by reference and call by pointer (with example if possible).
41
by: Summercool | last post by:
Can we confirm the following? also someone said, Java also has "reference" like in C++, which is an "implicit pointer": Pointer and Reference --------------------- I am starting to see what...
31
by: huili80 | last post by:
Say I have two classes: class A { public: int x; }; class B {
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.