Monday, August 7, 2017

Digest for comp.lang.c++@googlegroups.com - 12 updates in 5 topics

Juha Nieminen <nospam@thanks.invalid>: Aug 07 11:38AM

> type is a reference type, the variable can /store/ a
> reference( value). (JLS8, 4.1).
 
> (A reference( value) is a pointer [JLS8, 4.3.1].)
 
He probably meant that in Java non-primitive variables cannot be
accessed by any other means than by a reference.
 
(Also, a Java reference might not be directly pointing to the value
it's referring to, as is the case in C++. Quite often it will have
at least one level of indirection.)
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Aug 07 05:00PM +0200

On 07.08.2017 13:38, Juha Nieminen wrote:
 
> (Also, a Java reference might not be directly pointing to the value
> it's referring to, as is the case in C++. Quite often it will have
> at least one level of indirection.)
 
Practically true, but worth noting that strictly speaking it's not the
case that pointers have no indirection C++.
 
Consider the common Windows PC platform. With a conventional C++
implementation used to create an ordinary program, the statements
 
int x;
int* p = &x;
 
will store a logical address in `p`.
 
This address is resolved, when you do e.g. `*p = 42`, through two layers
of indirection. First (on the PC platform), it's treated as an offset in
a segment. Happily both the data and code segment selectors (processor
segment registers) are configured to refer to the same segment, so we
happily code away as if we have one big linear address space. Though C++
supports different address spaces for code and data.
 
Second, after the logical address has been resolved to a
whatchammacallit actual linear address space address, it's treated as
number of bit fields that specify page tables and offsets in these
tables. Commonly a page is a 4 KB chunk of physical memory. This is
mainly in support of virtual memory, but it's also nice for e.g. setting
execution protection flags, read-only, and such, not to mention deferred
allocation of physical memory for the machine stack (its logical address
range must be reserved up front, but actual physical memory, pages, can
be allocated automatically as needed, keeping that to a minimum).
 
That's a lot going on for a simple pointer dereference: accessing a
segment descriptor table, and IIRC at least two page tables, before
finally getting a physical memory address. In the course of this, memory
contents may swapped out to and retrieved from persistent storage!
 
So how come that you as a C++ programmer don't notice?
 
One doesn't notice because all that is encapsulated in the effect of
`*p`. And ditto for use of a Java reference.
 
It so happens that with C++ the indirection is usually only the hardware
supported one, while with Java there can be additional indirection at
the purely software level. And possibly a Java object can then be moved
around without updating more than a single pointer to it.
 
 
Cheers!,
 
- Alf
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Aug 07 05:27PM +0100

On 07/08/2017 16:00, Alf P. Steinbach wrote:
> the purely software level. And possibly a Java object can then be moved
> around without updating more than a single pointer to it.
 
> Cheers!,
 
+1
 
Thanks for confirming that Java uses pointers in such an informative
manner; Stuckle take note.
 
/Flibble
woodbrian77@gmail.com: Aug 07 11:07AM -0700

On Monday, August 7, 2017 at 11:28:05 AM UTC-5, Mr Flibble wrote:
 
> +1
 
> Thanks for confirming that Java uses pointers in such an informative
> manner; Stuckle take note.
 
Java dreary. C++ interesting.
 
 
Brian
Ebenezer Enterprises
http://webEbenezer.net
Manfred <noname@invalid.add>: Aug 07 09:53PM +0200

On 8/7/2017 5:00 PM, Alf P. Steinbach wrote:
>> at least one level of indirection.)
 
> Practically true, but worth noting that strictly speaking it's not the
> case that pointers have no indirection C++.
 
I disagree: C++ (and C) pointers have no indirection as far as the
language goes, and its implementation too.
 
The fact is that what you refer to is not part of any language
implementation: it is how the hardware and the OS handle virtual memory.
More precisely, virtual memory is a technology that is supported by
modern CPUs (including the good old 80386 and subsequent processors)
that expose a virtual (either linear or segmented) address space to
processes, that is converted into paged (and/or swapped) memory storage
/internally/ by the processor. Support from the OS is also required to
set up all required structures and operations, including a.o. context
switching between processes (which are each assigned its virtual address
space), and swap storage management.
 
When I say managed /internally/ by the processor, I mean that any
userspace process code that needs to access memory does so by setting
some memory register (e.g. rdi) with an address in /virtual/ address
space, and the conversion into physical memory address is performed by
the hardware - there is no userspace process code for this. Even in the
case of a page fault, the CPU raises an exception which is handled by OS
code to load the page from swap space - this is all transparent to
userspace code.
From the Intel software developer manual:
"When an operating system or executive uses paging, the paging mechanism
is transparent to an application program. All that the application sees
is linear address space."
 
Not even userspace asm code can see this - in order to modify the
virtual memory system, privileged instructions are required.
 
This is how any program that is compiled into native machine code runs,
there is no language interaction with any of this.
By the way, virtual address resolution in the CPU is /fast/, it is
optimized directly in the silicon, since protected mode "is the native
operating mode of the processor" (from Intel's "system programming guide")
 
Java pointers indirection has nothing to do with virtual memory
addressing, since a Java program is hosted inside the Java VM (i.e. the
Java runtime that is the Java interpreter), an it is the Java VM that is
the actual process that runs on the CPU. Anything that happens in a Java
program happens on top of the Java runtime.
This is why I wrote in another thread that a Java reference/pointer is a
handle instead of a memory address, since it references an object that
is hosted by the runtime, and not an object that is directly allocated
in RAM as for a C and C++ object.
 
This may not be that much of a difference with respect to pointer
semantics (although it is in specific cases), but it is a substantial
difference in how pointer operation is implemented.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Aug 07 10:10PM +0200

On 07.08.2017 21:53, Manfred wrote:
>> case that pointers have no indirection C++.
 
> I disagree: C++ (and C) pointers have no indirection as far as the
> language goes, and its implementation too.
 
Well, the first part is right, the part after the comma is IMO an
unwarranted assumption.
 
Are you aware that C++ interpreters exist?
 
Did you know that there are C++ compilers for virtual machines,
including for .NET (call it CLI or whatever)?
 
 
 
> This may not be that much of a difference with respect to pointer
> semantics (although it is in specific cases), but it is a substantial
> difference in how pointer operation is implemented.
 
I would be interested in the "specific cases".
 
 
Cheers!,
 
- Alf
Manfred <noname@invalid.add>: Aug 07 11:45PM +0200

On 08/07/2017 10:10 PM, Alf P. Steinbach wrote:
 
> Are you aware that C++ interpreters exist?
 
> Did you know that there are C++ compilers for virtual machines,
> including for .NET (call it CLI or whatever)?
 
I was referring to compiled C++ code, not to interpreters.
 
>> semantics (although it is in specific cases), but it is a substantial
>> difference in how pointer operation is implemented.
 
> I would be interested in the "specific cases".
 
These would be e.g. cases like setting a C++ pointer to a specific
address value - memory mapped registers come to mind. Other cases would
be pointer arithmetic - if I am not mistaken you can't do it in Java.
In these cases pointer semantics is substantially different between
C/C++ and Java.
 
ram@zedat.fu-berlin.de (Stefan Ram): Aug 07 09:36PM

>I would be interested in the "specific cases".
 
The meaning of »pointer« for C++ (comp.lang.c++) is defined
in ISO/IEC 14882. The meaning of »pointer« for Java
(comp.lang.java.programmer) is defined in the JLS. Both
specifications might be implicit or vague and might not
agree with each other.
 
A reference in Java is like a restricted C++ pointer: It
cannot be printed or converted to any other data type or
even be dereferenced, it can only be stored and passed and
be used to access fields and methods of the object it refers
to. There is no arithmetic with references.
 
There also are weak references which do not keep an object
alive IIRC. But there is no way to observe their handleness
via Java AFAIK.
"Tristan B. Kildaire" <deavmi@disroot.org>: Aug 07 06:48PM +0200

On 2017-08-04 09:52 PM, Rick C. Hodgin wrote:
> lives, including our labor hours, and our other hours.
 
> Thank you,
> Rick C. Hodgin
We need GCC-Jesus.
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Aug 07 01:00PM -0400

On 8/7/2017 12:48 PM, Tristan B. Kildaire wrote:
>> the things we do, so that we are honoring Him with the fullness of our
>> lives, including our labor hours, and our other hours.
 
> We need GCC-Jesus.
 
 
GCC is the GNU Compiler Collection, and it is run by GNU, an entity
started by Richard Stallman. Richard has some heinous views on things,
and as a result of me discovering these things about him, I could no
longer support his endeavor because of this truth:
 
http://biblehub.com/proverbs/29-12.htm
12 If a ruler listens to lies, all his officials become wicked.
 
As such, I created an alternate organization, the Liberty Software
Foundation (LibSF instead of FSF) and I created a new project called
the Village Freedom Project (VFrP instead of GNU).
 
The product I am working toward is called CAlive, and is a C-like
compiler built for the express purpose of honoring God with our
talents and labor, giving back to Him the fruit of what He first
gave us for free (our innate abilities, and the opportunities we've
had in this world to learn and grow and improve and achieve).
 
It is an ongoing endeavor, and people will come on board eventually
as the reality of the underlying philosophy begins to sink in, and
a true understanding of the purpose and intent is realized.
 
https://groups.google.com/forum/#!forum/caliveprogramminglanguage
https://groups.google.com/forum/#!forum/rapid_development_compiler
 
RDC -- Rapid Development Compiler is like the GCC framework.
CAlive -- A C-like language built within RDC, the first of many
languages that are planned, including a Java-like port, a C#-like
port, an eventual full virtual machine like .NET, a Julia-like
port, and as many others as people want to implement, because
once RDC is completed, people will be able to define any new
languages in a few months worth of work.
 
-----
That is the vision. That is the goal. I am doing it unto the
Lord acknowledging all He first gave me, and then for mankind so
that those things He first gave me are of benefit to others, and
not a burden to them financially, or through such things as the
invented concept of intellectual property.
 
Thank you,
Rick C. Hodgin
woodbrian77@gmail.com: Aug 07 07:42AM -0700

From reading over the upcoming talks at Cppcon:
 
https://cppcon.org/
 
it sounds like there's some interesting work going on
with C++.
 
 
 
Brian
Ebenezer Enterprises - Enjoying programming again.
http://webEbenezer.net
bitrex <bitrex@de.lete.earthlink.net>: Aug 06 10:36PM -0400

On 08/03/2017 06:48 PM, Mr Flibble wrote:
> myself.
 
> You have a lot to learn Padawan.
 
> /Flibble
 
Ah, the "books make ya soft" variety. Well, I agree. Whenever people
tell me about some book they read and the things in it I sadly shake my
head and say "Yeah, well you know what? You know who also read books?
....Hitler. Hitler read books."
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: