"Mastering C Pointers"....

B

Bruno Desthuilliers

Irrwahn Grausewitz wrote:
(snip)
(about Alan Connor)
I had some spare time and did a quick google groups search. If you're
only interested in the highlights, do a search for threads that have his
name in the _subject-line_. For the full load perform a search for
articles he posted. It's real fun.

Wow ! I'm impressed ! Everyone should have a look !
Bruno
 
J

John Kordyback

Chris said:
(As an aside: on modern operating systems, "memory" is usually an
illusion anyway. The OS will *simulate* a nice linear sequence of
bytes, but it does so with "pages" that are "paged in" and "paged
out" to/from some form of "backing store" -- typically on disk --
and shuffled and reshuffled without any individual program, whether
coded in C or any other language, being able to see what is happening.
The hardware must provide a certain amount of assistance to let
the OS know what a program is trying to do, and the OS then determines
whether the code is doing something "normal" and "allowed", and if
so, arranges to allow it. The OS can then also determine whether
the program is running amok, and if so, stop it. While large chunks
of OSes can be written in nothing other than strictly conforming
C code, parts *must* be written using stuff outside the C standard,
and often must be hand-coded in assembly. These include the parts
that talk with hardware to find out what the various user programs
are attempting.)
>

Are you talking about accessing memory through segmented memory spaces
by segment registers or access through the virtual memory page table? or
both?

Thanks..qb

P.S. Fascinating post by the way.
 
D

Dave Thompson

Chris Torek said:
For something really different, I would suggest trying [list of
"different" machines]

Shouldn't the HP3000 running MPE fit in there somewhere? I
believe it just became unsupported. Many Burroughsisms. It DID
have a C compiler 25 years ago.

Well, 25 years ago was 1987, which predates ANSI C, but mainly I
did not list it because I never used it nor even read much about
it. (I have not used the AS/400 either, but I have read a bit from
those who have.) I think certain Tandem machines might also fit
in the "oddball" category.
The original Tandem architecture, now known (more or less) as TNS1,
embedded as a core in the successor TNS2 which is still supported in
emulation though fading somewhat, had the (8-bit-)byte pointer versus
(16-bit-)word pointer issue. TNS1 had another (even odder?) feature,
that code is not only in a separate segment (like PDP-11 I&D-space
models) but (and still in TNS2) function pointers use a completely
different representation, so that even if a compiler is persuaded to
issue instructions to access code space using a pointer, doing so
using a function pointer doesn't get you to that function -- at best,
if you twiddle some bits, it gets you to an entry or exit vector slot
*for* the function. Of course in standard C you can't do anything with
a function pointer but remember it and call through it, which works.

And as long as someone brought up HP3k, another unusual feature of TNS
is that it does most (but not all!) computational operations in a
(register) stack-oriented fashion -- LOAD x; LOAD y; SUB; STOR z --
(very) vaguely similar to that machine. But since C never requires any
variables, even those marked 'register', to actually be in registers,
limitation on directly accessing registers is not a real problem.

- David.Thompson1 at worldnet.att.net
 
D

Dave Thompson

On 3 Nov 2003 14:54:00 -0800, (e-mail address removed) (August
Derleth) wrote:
Then I guess you never learned the beauty that is VAX, I suppose?
More's the pity: Understanding some of the intricacies of the DEC
minicomputers can help you grasp why some of C's crucial early design
decisions were made the way they were. For example, a flat memory
model and the whole notion of pre[increment|decrement] being usefully
different from post[increment|decrement] both came directly from the
PDPs.
Part of that seems to be an urban legend. If you believe dmr, his
2HOPL paper available at http://cm.bell-labs.com/cm/cs/who/dmr/ says
{pre,post}{inc,dec} were in B on PDP-7, which did not have them in
hardware. And PDP-11 had only postinc and predec for (primitive)
pointers, which became the idiomatic usage.

The flat memory model came from, and indeed was even stronger in,
BCPL, which AFAICT existed on mainframes before it saw any DEC, though
it seems to have become most widespread on PDP-10.
Truly, C was designed to be somewhere between PDP-11 assembly and
PL/1, but closer to assembly in some key ways.
Not PDP-11 specifically, but between the machine/assembly level of the
"average" minicomputer and something like PL/I or algol, yes; as were
several other System Implementation Languages of the day.
And I think learning PDP-8 assembly is what seperates the men from the
boys, esepcially if you can only use the 8 `actual' opcodes. ;)

Well, I learned -8 assembly (really, machine) as a boy (of 15), and it
didn't aid my maturation or status. I'm not sure what you mean by that
"only" -- you have to write out IOT 031 (IIRC) instead of KSF? Is that
really a big deal? But the -10 was definitely cooler; what other
machine carefully documents which no-ops (including unsuffixed JUMP
and SKIP) are faster than others? Or where a single instruction can
take forever, due to indirection loop?

- David.Thompson1 at worldnet.att.net
 
C

Chris Torek

Are you talking about accessing memory through segmented memory spaces
by segment registers or access through the virtual memory page table? or
both?

Either, both, or perhaps even neither, depending on the hardware.

One of the recently-popular hardware methods of implementing virtual
memory uses an "inverted page table" instead of the usual
tree-structured page tables. Whether this counts as a "page table"
depends on who does the counting, as it is a "page table", but
"inverted" so not really. :) In practice, the method is: on a
TLB miss, attach the current "unique address-space identifier" to
the virtual address, feed that through some kind of hash function,
and look in a global table entry based on the result. Expressed
in C it looks like this:

if ((found = tlb_search(id, vaddr, &paddr, &permissions)) == 0) {
index = hash(id, addr);
/*
* Hardware may do N of these, either sequential
* or rehashed.
*/
if (global_table[index].id == id &&
global_table[index].vaddr == vaddr) {
paddr = global_table[index].paddr;
permissions = global_table[index].permissions;
found = 1;
}
}
if (!found || wrong_permissions())
take_hardware_exception();

A conventional "forward" page table lookup usually divides up the
virtual address in some way and does 3 or 4 table lookups on each
piece, with each table's output being an input to the next. The
very top level table is often (but not always) called a "segment"
table.

Some hardware imposes neither "regular" nor "inverted" page tables.
MIPS and SPARC CPUs, for instance, implement only the TLB lookup
part of the process. If the TLB search misses, everything else is
up to software.

Fortunately, dealing with all this is normally an OS's job --
ordinary C code just sees ordinary, "locally flat" memory. Even
if each data object is stored in a separate segment, the contiguous
bytes that make up one object have nice linear addressing, as
handled by simple pointer arithmetic. But one could imagine a
system in which the C compiler provides the "OS-like functions" on
a modern paged CPU. Here pointer arithmetic like "p+3" might have
to consult any page tables to see if the new address is somewhere
over the rainbow.
 
M

Mark McIntyre

On 17 Nov 2003 23:28:38 -0800, in comp.lang.c , (e-mail address removed) (J. J.
Farrell) wrote:

(discussing of all things, I'm Sorry, I Haven't a Clue.)
New series just started. You can listen to each episode for a
week after transmission on Monday evenings.

http://www.bbc.co.uk/radio4/comedy/clue.shtml

I especially liked the idea of singing "The Red Flag" to the tune of
"Bring me Sunshine". For those of you not familiar with the latter
song, it was the rather jolly theme tune to The Morcambe and Wise
Show, another mildly insane british comedy series.

Excuse me while I skip off into the wings with Angela Rippon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top