Discussion:
16:32 far pointers in OpenWatcom C/C++
(too old to reply)
Jonathan de Boyne Pollard
2010-03-22 09:56:03 UTC
Permalink
I believe the Watcom 32 bit compilers can (or could, maybe removed by
now) large model (16 bit selector, 32 bit offset) code.
OpenWatcom version 1.9 is currently at its first release candidate.
16:32 far pointer support is, to the best of my knowledge, still there.
There's no reason to remove it. Indeed, the far pointer capabilities of
the compiler have been worked on by the developers for this release.
(Initialization of 16:16 far pointers with static storage duraction has
been improved. See the release notes for details.)
It might be that OS/2 know what to do with that, I don't believe any
other OS does.
One tends to use that sort of thing for systems programming, rather than
applications programming. In the case of OS/2, for example, there's not
much scope for using 16:32 far pointers in applications code, which is
almost always the Tiny model for 32-bit programs, but in kernel mode
code there are at least a couple of 32-bit segments that one might want
to work with using far pointers.
Ian Collins
2010-03-22 10:08:16 UTC
Permalink
On 03/22/10 10:56 PM, Jonathan de Boyne Pollard wrote:

Please stop this asinine cross posting.
--
Ian Collins
Kenny McCormack
2010-03-22 14:59:35 UTC
Permalink
Post by Ian Collins
Please stop this asinine cross posting.
(Reading in comp.lang.c, the funniest and most entertaining newsgroup on
the Usenet)

Yes, I was just about to ask where the CLC topicality police were hiding
out and why they were ignoring this thread. I was about to make the
usual comment about the double standard - how only the newbies get
pounded on for being "OT".

Thanks Ian - you've restored my faith in (what passes for ... in CLC)
humanity.
--
(This discussion group is about C, ...)

Wrong. It is only OCCASIONALLY a discussion group
about C; mostly, like most "discussion" groups, it is
off-topic Rorsharch revelations of the childhood
traumas of the participants...
1022 guy
2010-03-22 17:51:03 UTC
Permalink
Please stop crossposting to alt.sys.pdp10
Jonathan de Boyne Pollard
2010-03-22 21:51:52 UTC
Permalink
Post by Kenny McCormack
Yes, I was just about to ask where the CLC topicality police were
hiding out and why they were ignoring this thread.
Yes. Heaven forbid that the world should discuss a C compiler and the C
language in newsgroups relevant to that compiler and the C language!
Emily PostNews would have a fit. I'm not sure how Ian Collins expects
the rest of us to stop his so-called "asinine" cross-posting for him,
though.

Returning to what we were talking about before the silly diversion, I
should point out that 32-bit applications programming where the target
is extended DOS or 32-bit Win16 (with OpenWatcom's extender) will also
occasionally employ 16:32 far pointers of course. But as I said before,
regular 32-bit OS/2 or Win32 applications programming generally does
not, since those both use the Tiny memory model, and 16:32 far pointers
are generally confined to the realms of systems programming on the
relevant operating systems. (Systems programming on Windows NT usually
will not involve them, since the gory details of specialized I/O and
memory accesses are abstracted away within C/C++ macros and library
functions for systems programmers on Windows NT. But systems
programming on DOS-Windows 9x/ME and OS/2 may well.)
Peter Flass
2010-03-23 10:51:18 UTC
Permalink
Post by Jonathan de Boyne Pollard
Returning to what we were talking about before the silly diversion, I
should point out that 32-bit applications programming where the target
is extended DOS or 32-bit Win16 (with OpenWatcom's extender) will also
occasionally employ 16:32 far pointers of course. But as I said before,
regular 32-bit OS/2 or Win32 applications programming generally does
not, since those both use the Tiny memory model,
Flat memory model.
Branimir Maksimovic
2010-03-23 11:09:56 UTC
Permalink
On Tue, 23 Mar 2010 06:51:18 -0400
Post by Peter Flass
Post by Jonathan de Boyne Pollard
Returning to what we were talking about before the silly diversion,
I should point out that 32-bit applications programming where the
target is extended DOS or 32-bit Win16 (with OpenWatcom's extender)
will also occasionally employ 16:32 far pointers of course. But as
I said before, regular 32-bit OS/2 or Win32 applications
programming generally does not, since those both use the Tiny
memory model,
Flat memory model.
Problem with standard C and C++ is that they assume flat memory
model.
Eg pointer to char can have more than one type, in different
addressing modes.
It's not covered by standard. Since C and C++ aren't designed
to run in virtual machine, those are real problems.
Obvious advantage of segmented architecture is memory saving
you get for using short pointers , when appropriate.
Imagine just how memory is wasted in 64 bit environment...
"
In 64-bit mode (a sub-mode of IA-32e mode), a near pointer is 64 bits. This
equates to an effective address. Far pointers in 64-bit mode can be one of three
forms:
• 16-bit segment selector, 16-bit offset if the operand size is 32 bits
• 16-bit segment selector, 32-bit offset if the operand size is 32 bits
• 16-bit segment selector, 64-bit offset if the operand size is 64 bits
"
So, problem with flat model is that it is *not* most effective when
you waste 8 bytes for pointer that could take half of that!


Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Hans-Bernhard Bröker
2010-03-23 20:12:17 UTC
Permalink
Post by Branimir Maksimovic
Problem with standard C and C++ is that they assume flat memory
model.
No, that's not a problem, because they assume no such thing.

What they do assume is a _consistent_ memory model. I.e. they assume
that all code becoming part of the final program was built with the same
choice of memory model (by translators interpreting that choice in the
same way).

It's only when you _mix_ memory models that you run into problems with
standard compliance of the source code.
Post by Branimir Maksimovic
Eg pointer to char can have more than one type, in different
addressing modes.
But that's not an issue of memory model as such. You can only have
those different addressing modes in a program if you use constructs
outside that don't exist in standard language (stuff like far, near,
asm, ...).
Wilton Helm
2010-03-24 15:52:50 UTC
Permalink
Post by Hans-Bernhard Bröker
It's only when you _mix_ memory models that you run into problems with
standard compliance of the source code.
While that is mostly true, I suspect there are a few exceptions. The
compiler can hide the details of some segment operations going on behind the
scenes, but when you start dealing with arrays that are larger than
segments, or things like DMA that need linear address, the standard just
didn't really consider them. For 99% of programs memory model can be set
and forgotten, but there is that other 1%.

I recently asked for a bunch of pain by building a program with small model
that has two code segments and two data segments. It makes sense for the
situation, and is mostly working at the moment, but it is a perfect model of
mixing memory models. I've gotten bit a couple of times by jumps to code
pointers that had to be fixed, but mostly every data pointer has to be
evaluated to see if it is near or based. The hardest thing is where a based
pointer is typecast, because the typecast must also be based, since it
overrides the definition.

Wilton
Peter Flass
2010-03-23 21:42:32 UTC
Permalink
Post by Branimir Maksimovic
On Tue, 23 Mar 2010 06:51:18 -0400
Post by Peter Flass
Post by Jonathan de Boyne Pollard
Returning to what we were talking about before the silly diversion,
I should point out that 32-bit applications programming where the
target is extended DOS or 32-bit Win16 (with OpenWatcom's extender)
will also occasionally employ 16:32 far pointers of course. But as
I said before, regular 32-bit OS/2 or Win32 applications
programming generally does not, since those both use the Tiny
memory model,
Flat memory model.
Problem with standard C and C++ is that they assume flat memory
model.
I'm not a C expert, perhaps you're a denizen of comp.lang.c, but as far
as I know there's nothing in the C standard that assumes anything about
pointers, except that they have to be the same size as int, so for 16:32
pointers I guess you'd need 64-bit ints.

As far as implementations are concerned, both Watcom and IBM VA C++
support segmented memory models. These are the ones I'm aware of, there
are probably more.
Branimir Maksimovic
2010-03-23 22:08:46 UTC
Permalink
On Tue, 23 Mar 2010 17:42:32 -0400
Post by Peter Flass
Post by Branimir Maksimovic
On Tue, 23 Mar 2010 06:51:18 -0400
Post by Peter Flass
Post by Jonathan de Boyne Pollard
Returning to what we were talking about before the silly
diversion, I should point out that 32-bit applications
programming where the target is extended DOS or 32-bit Win16
(with OpenWatcom's extender) will also occasionally employ 16:32
far pointers of course. But as I said before, regular 32-bit
OS/2 or Win32 applications programming generally does not, since
those both use the Tiny memory model,
Flat memory model.
Problem with standard C and C++ is that they assume flat memory
model.
I'm not a C expert, perhaps you're a denizen of comp.lang.c, but as
far as I know there's nothing in the C standard that assumes anything
about pointers, except that they have to be the same size as int, so
for 16:32 pointers I guess you'd need 64-bit ints.
No, 32. You would load 16 bit selector into segment register.

Regarding 64 bit mode on Intel, segmentation is disabled, not
used, none, but you can save on memory if you are using 32
bit operands and you don;t need more than 4gb of ram.
So basically you can program like in 32 bit mode almost
completely (stack requires different alignment dough)
but you can save on memory if you could have
both 32 bit and 64 bit pointer to char eg.
This is not about segmentation, but memory savings.
Of course, you can always, compile as 32 bit ;),
or I guess there are 64 bit mode switches to
choose sizes, but AMD made it that way that you can
actually *mix* 32 bit with 64 it code ;)

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Hans-Bernhard Bröker
2010-03-23 22:25:50 UTC
Permalink
Post by Peter Flass
I'm not a C expert, perhaps you're a denizen of comp.lang.c, but as far
as I know there's nothing in the C standard that assumes anything about
pointers,
You know incorrectly, then. There are some requirements about pointers
in the C standard.

except that they have to be the same size as int,

That's _not_ in the C standard. Nor anything like it.
Flash Gordon
2010-03-23 22:14:42 UTC
Permalink
Post by Peter Flass
Post by Branimir Maksimovic
On Tue, 23 Mar 2010 06:51:18 -0400
Post by Peter Flass
Post by Jonathan de Boyne Pollard
Returning to what we were talking about before the silly diversion,
I should point out that 32-bit applications programming where the
target is extended DOS or 32-bit Win16 (with OpenWatcom's extender)
will also occasionally employ 16:32 far pointers of course. But as
I said before, regular 32-bit OS/2 or Win32 applications
programming generally does not, since those both use the Tiny
memory model,
Flat memory model.
Problem with standard C and C++ is that they assume flat memory
model.
I'm not a C expert, perhaps you're a denizen of comp.lang.c, but as far
as I know there's nothing in the C standard that assumes anything about
pointers, except that they have to be the same size as int, so for 16:32
pointers I guess you'd need 64-bit ints.
There is no requirement in the standard that pointers are the same size
as int. In fact, there is no requirement that there is *any* integer
type the same size (or as large as) a pointer. There is also no
requirement that pointers of all types are the same size.
Post by Peter Flass
As far as implementations are concerned, both Watcom and IBM VA C++
support segmented memory models. These are the ones I'm aware of, there
are probably more.
I'm sure there have been a number of processors with segmented
architectures, and that a number of them will have had C compilers, so
there are almost certainly more.
--
Flash Gordon
E. S. Fabian
2010-03-24 00:35:27 UTC
Permalink
Flash Gordon wrote:
| I'm sure there have been a number of processors with segmented
| architectures, and that a number of them will have had C compilers,
| so there are almost certainly more.

The IBM 360 mainframe line (designed in the early 1960-s) is probably the
earliest segmented architecture, but it never had the limitations of the
Intel architecture. Register size was 32 b, regardless of the width of the
memory bus (which was available in all power-of-two sizes from 8-b to 128-b
width, depending on your budget), and registers could address all memory.
All pointers were flat model pointers.
--
Steve
Jonathan de Boyne Pollard
2010-03-25 02:29:00 UTC
Permalink
Post by E. S. Fabian
Post by Flash Gordon
I'm sure there have been a number of processors with segmented
architectures, and that a number of them will have had C compilers,
so there are almost certainly more.
The IBM 360 mainframe line (designed in the early 1960-s) is probably
the earliest segmented architecture, but it never had the limitations
of the Intel architecture. Register size was 32 b, regardless of the
width of the memory bus (which was available in all power-of-two sizes
from 8-b to 128-b width, depending on your budget), and registers
could address all memory. All pointers were flat model pointers.
We were discussing the 68xx and 680x0 processors earlier in this thread,
and the reasons to like them. Having general-purpose registers that
were as big as full memory addresses (at the instruction set level) is
definitely one such reason. It raises an interesting question, though.
How many CPUs in the modern personal computer market, or indeed in the
modern computer market overall, is that still true of? Not having
general-purpose registers as wide as memory addresses has long been the
case for the majority (given the popularity of the x86 architecture).
But has it now become universally the case?
E. S. Fabian
2010-03-24 00:23:17 UTC
Permalink
Peter Flass wrote:
| I'm not a C expert, perhaps you're a denizen of comp.lang.c, but as
| far as I know there's nothing in the C standard that assumes
| anything about pointers, except that they have to be the same size
| as int, so for 16:32 pointers I guess you'd need 64-bit ints.

No, you'd need a 48-bit integral type, but in fact no C standard requires
any specific size for pointers at all, and the only requirements for integer
types are minima: 8b for char, 16b for short, and 32b for long. int may be
as small as short, and may not be larger than long. All of them (char,
short, int, and long) can be the same size!
--
Steve
Richard Bos
2010-03-24 09:48:12 UTC
Permalink
Post by Peter Flass
Post by Branimir Maksimovic
Problem with standard C and C++ is that they assume flat memory
model.
Nonsense.
Post by Peter Flass
I'm not a C expert, perhaps you're a denizen of comp.lang.c, but as far
as I know there's nothing in the C standard that assumes anything about
pointers, except that they have to be the same size as int,
There is absolutely nothing in the C Standard that requires pointers to
have the size of int, or even the size of anything whatsoever, except
that
- void pointers and char pointers shall have the same representation
(and therefore size) as one another - _not_ necessarily as any other
kind of pointer, though since void pointers must be able to be freely
convertible from and to other object pointers, it takes a perverted
implementation to make them _smaller_ than other object pointers (but
perversion, though not advised, is allowed implementation authors);
- pointers to const <foo> must have the same representation as pointers
to <foo> and vice versa, and ditto for volatile and restrict;
- all pointers to struct must have the same representation, and all
pointers to union (but struct pointers need not be the same as union
pointers; again, it would usually be silly not to have them be, but
it's allowed).
Nothing about ints there.

Richard
Branimir Maksimovic
2010-03-24 09:57:37 UTC
Permalink
On Wed, 24 Mar 2010 09:48:12 GMT
Post by Richard Bos
Post by Branimir Maksimovic
Problem with standard C and C++ is that they assume flat memory
model.
Nonsense.
Well, technically this is not nonsense. There are no built in
features to portably accommodate different memory models.
Problem is that sizeof(char*) can be realistically
in some situation 4 bytes in other 8 bytes , and
third 2 bytes even in same function.
Is this allowed by standard C and C++?
If this is allowed then yes, C and C++ does not assume
flat memory model.

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Ahem A Rivet's Shot
2010-03-24 11:16:06 UTC
Permalink
On Wed, 24 Mar 2010 10:57:37 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 09:48:12 GMT
Post by Richard Bos
Post by Branimir Maksimovic
Problem with standard C and C++ is that they assume flat memory
model.
Nonsense.
Well, technically this is not nonsense. There are no built in
features to portably accommodate different memory models.
Problem is that sizeof(char*) can be realistically
in some situation 4 bytes in other 8 bytes , and
third 2 bytes even in same function.
Is this allowed by standard C and C++?
Having the underlying addressing mechanism of the processor use
different sizes of address for different contexts does not require a C
implementation to follow suit. Nothing requires C pointers to be addresses
they could be larger structures that include enough information for the
compiler to generate an address of the appropriate type when needed (or
otherwise retrieve the data being pointed to).
Post by Branimir Maksimovic
If this is allowed then yes, C and C++ does not assume
flat memory model.
It doesn't - all that C requires of pointers is that they can be
dereferenced, converted to void pointers and back again, and that adding
and subtracting integers works within certain well defined limits. Nothing
requires them to be machine addresses.
--
Steve O'Hara-Smith | Directable Mirror Arrays
C:>WIN | A better way to focus the sun
The computer obeys and wins. | licences available see
You lose and Bill collects. | http://www.sohara.org/
Branimir Maksimovic
2010-03-24 11:48:26 UTC
Permalink
On Wed, 24 Mar 2010 11:16:06 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 10:57:37 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 09:48:12 GMT
Post by Richard Bos
Post by Branimir Maksimovic
Problem with standard C and C++ is that they assume flat
memory model.
Nonsense.
Well, technically this is not nonsense. There are no built in
features to portably accommodate different memory models.
Problem is that sizeof(char*) can be realistically
in some situation 4 bytes in other 8 bytes , and
third 2 bytes even in same function.
Is this allowed by standard C and C++?
Having the underlying addressing mechanism of the processor
use different sizes of address for different contexts does not
require a C implementation to follow suit. Nothing requires C
pointers to be addresses they could be larger structures that include
enough information for the compiler to generate an address of the
appropriate type when needed (or otherwise retrieve the data being
pointed to).
Is it allowed to have different sizes of char* then in same program?
I mean what is advantage say int* over plain short/int/long/long long
as pointer into array, except easier dereferencing syntax?
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
If this is allowed then yes, C and C++ does not assume
flat memory model.
It doesn't - all that C requires of pointers is that they can
be dereferenced, converted to void pointers and back again, and that
adding and subtracting integers works within certain well defined
limits. Nothing requires them to be machine addresses.
Hm , how abstract C and C++ machine looks like? Is it flat
address space or segmented?
Problem is that we are talking about *pointers* and *pointer
arithmetic*. Actually integers are more useful than pointers,
for performance optimal code in both C and C++,
since they actually map to abstract machine address, unlike
pointers which can be slow, unoptimized (because of rules) and useless.
Alright int* can be base of segment eg after malloc,
but short can be used as pointer instead, since we cannot
count on different sizes of int*.
We just need that 'int*' , for scale factor in arithmetic.
I understand that char* requirement to be same size as void*,
follow historical reasons.

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Ahem A Rivet's Shot
2010-03-24 12:41:04 UTC
Permalink
On Wed, 24 Mar 2010 12:48:26 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 11:16:06 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 10:57:37 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 09:48:12 GMT
Post by Richard Bos
Post by Branimir Maksimovic
Problem with standard C and C++ is that they assume flat
memory model.
Nonsense.
Well, technically this is not nonsense. There are no built in
features to portably accommodate different memory models.
Problem is that sizeof(char*) can be realistically
in some situation 4 bytes in other 8 bytes , and
third 2 bytes even in same function.
Is this allowed by standard C and C++?
Having the underlying addressing mechanism of the processor
use different sizes of address for different contexts does not
require a C implementation to follow suit. Nothing requires C
pointers to be addresses they could be larger structures that include
enough information for the compiler to generate an address of the
appropriate type when needed (or otherwise retrieve the data being
pointed to).
Is it allowed to have different sizes of char* then in same program?
I mean what is advantage say int* over plain short/int/long/long long
as pointer into array, except easier dereferencing syntax?
I didn't say that there would be different sizes of char *, I said
that char * could be a fixed size structure which includes an address and an
indication of the size and type of that address something like this
internally:

struct pointer {
char type;
union {
uint16_t pointer16;
uint32_t pointer32;
uint64_t pointer64;
} ptr;
}

I'm not suggesting this is necessarily a good idea - just that it's
possible. The point is that C pointer types do not have to be machine
addresses.
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
If this is allowed then yes, C and C++ does not assume
flat memory model.
It doesn't - all that C requires of pointers is that they can
be dereferenced, converted to void pointers and back again, and that
adding and subtracting integers works within certain well defined
limits. Nothing requires them to be machine addresses.
Hm , how abstract C and C++ machine looks like? Is it flat
address space or segmented?
What abstract machine ?
Post by Branimir Maksimovic
Problem is that we are talking about *pointers* and *pointer
arithmetic*.
Yes C defines pointers and the rules for pointer arithmetic.
Post by Branimir Maksimovic
Actually integers are more useful than pointers,
Only if they're big enough - nothing prevents a C implementation
having no integer type bigger than 32 bits while pointers are (say) 48 bits.
Post by Branimir Maksimovic
for performance optimal code in both C and C++,
since they actually map to abstract machine address, unlike
Integers may not be able to map to machine addresses, that being
said it may well be more efficient to use a base pointer and an integer
offset than to manipulate pointers - but underneath it all C is going to be
manipulating pointers when you do that.
--
Steve O'Hara-Smith | Directable Mirror Arrays
C:>WIN | A better way to focus the sun
The computer obeys and wins. | licences available see
You lose and Bill collects. | http://www.sohara.org/
Branimir Maksimovic
2010-03-24 13:45:24 UTC
Permalink
On Wed, 24 Mar 2010 12:41:04 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 12:48:26 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 11:16:06 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 10:57:37 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 09:48:12 GMT
Post by Richard Bos
Post by Branimir Maksimovic
Problem with standard C and C++ is that they assume flat
memory model.
Nonsense.
Well, technically this is not nonsense. There are no built in
features to portably accommodate different memory models.
Problem is that sizeof(char*) can be realistically
in some situation 4 bytes in other 8 bytes , and
third 2 bytes even in same function.
Is this allowed by standard C and C++?
Having the underlying addressing mechanism of the
processor use different sizes of address for different contexts
does not require a C implementation to follow suit. Nothing
requires C pointers to be addresses they could be larger
structures that include enough information for the compiler to
generate an address of the appropriate type when needed (or
otherwise retrieve the data being pointed to).
Is it allowed to have different sizes of char* then in same program?
I mean what is advantage say int* over plain short/int/long/long
long as pointer into array, except easier dereferencing syntax?
I didn't say that there would be different sizes of char *, I
said that char * could be a fixed size structure which includes an
address and an indication of the size and type of that address
struct pointer {
char type;
union {
uint16_t pointer16;
uint32_t pointer32;
uint64_t pointer64;
} ptr;
}
I'm not suggesting this is necessarily a good idea - just
that it's possible. The point is that C pointer types do not have to
be machine addresses.
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
If this is allowed then yes, C and C++ does not assume
flat memory model.
It doesn't - all that C requires of pointers is that they
can be dereferenced, converted to void pointers and back again,
and that adding and subtracting integers works within certain
well defined limits. Nothing requires them to be machine
addresses.
Hm , how abstract C and C++ machine looks like? Is it flat
address space or segmented?
What abstract machine ?
What this mister is talking about then?

http://www.stanford.edu/group/sequoia/cgi-bin/node/15
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
Problem is that we are talking about *pointers* and *pointer
arithmetic*.
Yes C defines pointers and the rules for pointer arithmetic.
Post by Branimir Maksimovic
Actually integers are more useful than pointers,
Only if they're big enough - nothing prevents a C
implementation having no integer type bigger than 32 bits while
pointers are (say) 48 bits.
Problem is that integers are used to index into arrays.
Since arrays are identical to raw memory segment thanks to malloc,
ints must have capability to index maximum array/segment
size on architecture. So actually long long would be
enough big for maximum relative indexing of segment.
Since pointer arithmetic in C is identical with
array indexing, plain ints are actually C pointers
with relative addressing , while you p[revious explanation
shows that ordinary C pointers are actually absolute addressing
pointers with convenient syntax.
Actually implementation can identify any pointer with
int as they are identical to indexes into arrays,
but void* and char* has to be absolute addresses.
Good implementation can do that in order to
minimize memory usage for pointers other than
char* and void*. Only problem is that pointers
can be stored in memory as single type (I mean pointer to one type)
and that requires fixed size which is actually maximum array
size. Far/Near/Huge pointers came as necessity for practical
reasons on architectures where C abstract machine does not map 1-1.
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
for performance optimal code in both C and C++,
since they actually map to abstract machine address, unlike
Integers may not be able to map to machine addresses, that
being said it may well be more efficient to use a base pointer and an
integer offset than to manipulate pointers - but underneath it all C
is going to be manipulating pointers when you do that.
Of course. Think about malloc, what it returns and you
can cast that to *any type*. Brilliant thing.

Greets
--
http://maxa.homedns.org/

Sometimes online sometimes not
Ahem A Rivet's Shot
2010-03-24 14:06:28 UTC
Permalink
On Wed, 24 Mar 2010 14:45:24 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 12:41:04 +0000
Post by Ahem A Rivet's Shot
Only if they're big enough - nothing prevents a C
implementation having no integer type bigger than 32 bits while
pointers are (say) 48 bits.
Problem is that integers are used to index into arrays.
Well strictly speaking you need size_t in order to guarantee being
able to index into any array.
Post by Branimir Maksimovic
Since arrays are identical to raw memory segment thanks to malloc,
Nothing guarantees that.
Post by Branimir Maksimovic
ints must have capability to index maximum array/segment
size on architecture. So actually long long would be
enough big for maximum relative indexing of segment.
Nope size_t must be big enough for that, but there's no requirement
that any int type be as big as size_t.
Post by Branimir Maksimovic
Since pointer arithmetic in C is identical with
array indexing, plain ints are actually C pointers
with relative addressing ,
No ints are not C pointers they have *very* different arithmetic
rules.
Post by Branimir Maksimovic
while you p[revious explanation
shows that ordinary C pointers are actually absolute addressing
pointers with convenient syntax.
Actually implementation can identify any pointer with
int as they are identical to indexes into arrays,
but void* and char* has to be absolute addresses.
Pointers do not have to be any kind of address.
--
Steve O'Hara-Smith | Directable Mirror Arrays
C:>WIN | A better way to focus the sun
The computer obeys and wins. | licences available see
You lose and Bill collects. | http://www.sohara.org/
Branimir Maksimovic
2010-03-24 14:57:46 UTC
Permalink
On Wed, 24 Mar 2010 14:06:28 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 14:45:24 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 12:41:04 +0000
Post by Ahem A Rivet's Shot
Only if they're big enough - nothing prevents a C
implementation having no integer type bigger than 32 bits while
pointers are (say) 48 bits.
Problem is that integers are used to index into arrays.
Well strictly speaking you need size_t in order to guarantee
being able to index into any array.
Remember size_t is typedef. Can;t be float, can;t be pointer,
it has to be one of available ints.
Actually I don;t think size_t is any good for indexing into array.
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
Since arrays are identical to raw memory segment thanks to malloc,
Nothing guarantees that.
void* is raw memory, concerning C programmer. And malloc
returns pointer to raw memory segment that can be used
to store *any type*. array arithmetic, pointer arithmetic
are same. Since you pass size_t typedef to malloc,
actually int of largest block, can;t see inconsistency
in that.
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
ints must have capability to index maximum array/segment
size on architecture. So actually long long would be
enough big for maximum relative indexing of segment.
Nope size_t must be big enough for that, but there's no
requirement that any int type be as big as size_t.
And what size_t would be? Integer? float? pointer?
What you can pass to malloc?
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
Since pointer arithmetic in C is identical with
array indexing, plain ints are actually C pointers
with relative addressing ,
No ints are not C pointers they have *very* different
arithmetic rules.
I don;t think so. as *(a+i) is identical to a[i] or i[a]
and a automatically converts to pointer to first element.
Did you know that array subscript is associative?
Do you know why?
Only difference is that a+i increments by scale bytes, scale being
type that pointer points to.
But C memory model assumes absolute addressing.
You can't do b=a+i;c=a+b;
But you can decrement, since if you substract two absolute addresses
you can;t get out of segment bounds.
That is why it would be useful to have relative /absolute semantics.
Just because to avoid casting ints to pointers in order to
have convenient syntax for array indexing.
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
while you p[revious explanation
shows that ordinary C pointers are actually absolute addressing
pointers with convenient syntax.
Actually implementation can identify any pointer with
int as they are identical to indexes into arrays,
but void* and char* has to be absolute addresses.
Pointers do not have to be any kind of address.
http://en.wikipedia.org/wiki/Pointer_%28computing%29

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Branimir Maksimovic
2010-03-24 15:01:16 UTC
Permalink
On Wed, 24 Mar 2010 15:57:46 +0100
Post by Branimir Maksimovic
Did you know that array subscript is associative?
Commutative...
Ahem A Rivet's Shot
2010-03-24 15:27:48 UTC
Permalink
On Wed, 24 Mar 2010 15:57:46 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 14:06:28 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 14:45:24 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 12:41:04 +0000
Post by Ahem A Rivet's Shot
Only if they're big enough - nothing prevents a C
implementation having no integer type bigger than 32 bits while
pointers are (say) 48 bits.
Problem is that integers are used to index into arrays.
Well strictly speaking you need size_t in order to guarantee
being able to index into any array.
Remember size_t is typedef. Can;t be float, can;t be pointer,
it has to be one of available ints.
It doesn't have to be a typedef - it usually is but it doesn't have
to be.
Post by Branimir Maksimovic
Actually I don;t think size_t is any good for indexing into array.
Yes it is - it's the only type that's defined to be big enough to
index any array.
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
Since arrays are identical to raw memory segment thanks to malloc,
Nothing guarantees that.
void* is raw memory, concerning C programmer. And malloc
void* is a pointer such that any other pointer can be cast to void
* and back again without getting damaged.
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Nope size_t must be big enough for that, but there's no
requirement that any int type be as big as size_t.
And what size_t would be? Integer? float? pointer?
It would be perfectly valid to build a C compiler in which
int, long, long long are all 32 bits but size_t is 64 bits and pointer is
some convoluted structure with a memory address buried in it.
Post by Branimir Maksimovic
What you can pass to malloc?
You pass a size_t to malloc.
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
Since pointer arithmetic in C is identical with
array indexing, plain ints are actually C pointers
with relative addressing ,
No ints are not C pointers they have *very* different
arithmetic rules.
I don;t think so. as *(a+i) is identical to a[i] or i[a]
Provided that one of a and i is a pointer and the other is an
integer - if both a and i are pointers then this is not a valid expression,
likewise if both are integers this is not valid. Therefore pointers are not
the same as ints.
Post by Branimir Maksimovic
and a automatically converts to pointer to first element.
If a is an array - yes.
Post by Branimir Maksimovic
Did you know that array subscript is associative?
Do you know why?
Commutative - as you corrected yourself. Yes I do, it is
commutative because it is defined as being so.
Post by Branimir Maksimovic
Only difference is that a+i increments by scale bytes, scale being
type that pointer points to.
That is *one* very important difference, another is that adding a
pointer to an integer is only valid within certain limits having to do with
the original allocation or declaration of the object being pointed to
(basically between the first entry in an array and one past the end of an
array) - for example:

int *p;
int a[50];
p = &(a[0]);
p = p - 1;
p = p + 1;

It is no longer guaranteed that p points to a[0], yet another
important difference between pointer arithmetic and integer arithmetic.
Post by Branimir Maksimovic
But C memory model assumes absolute addressing.
You can't do b=a+i;c=a+b;
No you cannot add pointers.
Post by Branimir Maksimovic
But you can decrement, since if you substract two absolute addresses
you can;t get out of segment bounds.
C doesn't talk about segments.
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Pointers do not have to be any kind of address.
http://en.wikipedia.org/wiki/Pointer_%28computing%29
Is correct this far:

"In computer science, a pointer is a programming language data type whose
value refers directly to (or "points to") another value"

After that it strays into implementation detail which may or may
not be correct.
--
Steve O'Hara-Smith | Directable Mirror Arrays
C:>WIN | A better way to focus the sun
The computer obeys and wins. | licences available see
You lose and Bill collects. | http://www.sohara.org/
Keith Thompson
2010-03-24 18:49:16 UTC
Permalink
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 15:57:46 +0100
[...]
Post by Branimir Maksimovic
Post by Branimir Maksimovic
Remember size_t is typedef. Can;t be float, can;t be pointer,
it has to be one of available ints.
It doesn't have to be a typedef - it usually is but it doesn't have
to be.
How could size_t not be a typedef? It's not a keyword or a macro.
You can legally declare an object called "size_t" in a local scope
(not that it's a good idea). And you can invoke the sizeof operator
without the name size_t being visible.

sizeof yields a result of some predefined unsigned type. size_t is a
typedef for that type.

The standard doesn't say so explicitly; it says, in C99 7.17p2, that
size_t "is the unsigned integer type of the result of the sizeof
operator. If you can think of a way to satisfy that requirement
without making size_t a typedef (or any reason to do so), I'd
be interested.

[...]
Post by Branimir Maksimovic
It would be perfectly valid to build a C compiler in which
int, long, long long are all 32 bits but size_t is 64 bits and pointer is
some convoluted structure with a memory address buried in it.
Yes, but size_t needs to be a typedef for some unsigned integer type.
If it's bigger than unsigned long long, then it has to be an extended
integer type as described in C99 6.2.5.

[...]
--
Keith Thompson (The_Other_Keith) kst-***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Ahem A Rivet's Shot
2010-03-25 07:45:40 UTC
Permalink
On Wed, 24 Mar 2010 11:49:16 -0700
Post by Keith Thompson
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 15:57:46 +0100
[...]
Post by Branimir Maksimovic
Post by Branimir Maksimovic
Remember size_t is typedef. Can;t be float, can;t be pointer,
it has to be one of available ints.
It doesn't have to be a typedef - it usually is but it doesn't
have to be.
How could size_t not be a typedef? It's not a keyword or a macro.
It can be a type.
--
Steve O'Hara-Smith | Directable Mirror Arrays
C:>WIN | A better way to focus the sun
The computer obeys and wins. | licences available see
You lose and Bill collects. | http://www.sohara.org/
Branimir Maksimovic
2010-03-25 10:18:25 UTC
Permalink
On Thu, 25 Mar 2010 07:45:40 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 11:49:16 -0700
Post by Keith Thompson
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 15:57:46 +0100
[...]
Post by Branimir Maksimovic
Post by Branimir Maksimovic
Remember size_t is typedef. Can;t be float, can;t be pointer,
it has to be one of available ints.
It doesn't have to be a typedef - it usually is but it
doesn't have to be.
How could size_t not be a typedef? It's not a keyword or a macro.
It can be a type.
Is there any significant difference of C size_t and C++ size_t.
I know in C++, you have to include at least cstddef or stddef.h.
Always thought that size_t is just typedef for largest unsigned int.

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Ahem A Rivet's Shot
2010-03-25 11:48:42 UTC
Permalink
On Thu, 25 Mar 2010 11:18:25 +0100
Post by Branimir Maksimovic
On Thu, 25 Mar 2010 07:45:40 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 11:49:16 -0700
Post by Keith Thompson
How could size_t not be a typedef? It's not a keyword or a macro.
It can be a type.
Is there any significant difference of C size_t and C++ size_t.
I know in C++, you have to include at least cstddef or stddef.h.
Always thought that size_t is just typedef for largest unsigned int.
It usually is exactly that, but unless I'm very much mistaken it is
not required to be anything other than an integer type that can hold the
largest possible offset and nothing requires any other integer type to be
able to do so (except perhaps uintmax_t).
--
Steve O'Hara-Smith | Directable Mirror Arrays
C:>WIN | A better way to focus the sun
The computer obeys and wins. | licences available see
You lose and Bill collects. | http://www.sohara.org/
Branimir Maksimovic
2010-03-25 14:35:51 UTC
Permalink
On Thu, 25 Mar 2010 11:48:42 +0000
Post by Ahem A Rivet's Shot
It usually is exactly that, but unless I'm very much mistaken
it is not required to be anything other than an integer type that can
hold the largest possible offset and nothing requires any other
integer type to be able to do so (except perhaps uintmax_t).
Thanks for explanation.

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Keith Thompson
2010-03-24 18:15:05 UTC
Permalink
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 14:06:28 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 14:45:24 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 12:41:04 +0000
Post by Ahem A Rivet's Shot
Only if they're big enough - nothing prevents a C
implementation having no integer type bigger than 32 bits while
pointers are (say) 48 bits.
Problem is that integers are used to index into arrays.
Well strictly speaking you need size_t in order to guarantee
being able to index into any array.
Remember size_t is typedef. Can;t be float, can;t be pointer,
it has to be one of available ints.
It has to be an unsigned integer type.
Post by Branimir Maksimovic
Actually I don;t think size_t is any good for indexing into array.
Sure it is.

For a declared object of any type, ``sizeof object'' yields the size
in bytes of the object, with a result of type size_t. For an object
allocated by a call to malloc() the size argument to malloc is of
type size_t, so it can't create an object bigger than SIZE_MAX bytes.
(SIZE_MAX, as the name implies, is the largest possible value of
type size_t.)

Which means that, with the possible exception of some bizarre cases,
no object can be bigger than SIZE_MAX bytes. Since the elements
of an array must be at least 1 byte in size, it follows that the
maximum index for an array object cannot exceed SIZE_MAX.

size_t is the only integer type (other that uintmax_t) that has this
guarantee.

(The bizarre cases are things like calloc() with two arguments whose
product exceeds SIZE_MAX and large (possibly variable-length) arrays.
On most implementations, such objects can't created; calloc()
will return NULL and huge array object declarations will exceed
implementation limits. We've had some discussions here recently
about whether an implementation is, or should be, permitted to
support objects bigger than SIZE_MAX bytes.)

[...]
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Nope size_t must be big enough for that, but there's no
requirement that any int type be as big as size_t.
And what size_t would be? Integer? float? pointer?
What you can pass to malloc?
You're right, size_t is a typedef for some existing unsigned integer
type. (Note: "integer type" not "int type"; "int" is one specific
integer type.) But there's no guarantee that any int type is as
big as a pointer. A pointer can point to any object in memory;
size_t only needs to be big enough to span a single object.
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
Since pointer arithmetic in C is identical with
array indexing, plain ints are actually C pointers
with relative addressing ,
No ints are not C pointers they have *very* different
arithmetic rules.
I don;t think so. as *(a+i) is identical to a[i] or i[a]
and a automatically converts to pointer to first element.
Did you know that array subscript is associative?
Commutative, not associative, as you acknowledged in a followup.
Post by Branimir Maksimovic
Do you know why?
Because both pointer+integer and integer+pointer arithmetic are
supported (as well as pointer-integer and pointer-pointer). The
language *could* have required the pointer to appear on the LHS of the
"+", banning integer+pointer. The (unnecessary IMHO) symmetry goes
back to the early days of C, when the distinction between integers and
pointers wasn't as strong as it is now.
Post by Branimir Maksimovic
Only difference is that a+i increments by scale bytes, scale being
type that pointer points to.
Pointer addition is a different operation than integer addition.
Post by Branimir Maksimovic
But C memory model assumes absolute addressing.
Not really, though I suppose it depends on what exactly you mean by
"absolute addressing".
Post by Branimir Maksimovic
You can't do b=a+i;c=a+b;
But you can decrement, since if you substract two absolute addresses
you can;t get out of segment bounds.
That is why it would be useful to have relative /absolute semantics.
Just because to avoid casting ints to pointers in order to
have convenient syntax for array indexing.
I'm not sure what you're saying here, but in some of your other
articles in this thread I think you're conflating two different
things.

C requires all pointers of a given type to have the same size and
representation. char* and int* might be different, but any two
pointers to char are stored the same way. On some systems, it might
be convenient to be able to have different "flavors" of pointers to
the same type, where the different flavors might, for example, be able to
point to different regions of memory. On a 64-bit system, you might
want to have 64-bit pointers that can point anywhere, and 32-bit
pointers that can only point into the bottom 4GB of memory.

C doesn't support this. Pointers are distinguished only by the type
they point to. If I obtain a pointer to an int object, I can copy
that pointer value into any other pointer-to-int object and
dereference the copy without knowing or caring how the original
pointer was generated.

This kind of thing can be supported by an implementation-specific
extension, such as the "near" and "far" pointer types in some x86
compilers. But any code that uses such an extension is non-portable.

On the other hand, C does *not* assume a monolithic addressing space.
A C pointer might internally consist of a segment identifier plus
an offset into that segment. Pointer arithmetic might affect only
the offset.
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
while you p[revious explanation
shows that ordinary C pointers are actually absolute addressing
pointers with convenient syntax.
Actually implementation can identify any pointer with
int as they are identical to indexes into arrays,
but void* and char* has to be absolute addresses.
Pointers do not have to be any kind of address.
That depends on what you mean by "address". The C standard uses the
word to mean, essentially, a pointer value. But an address / pointer
value needn't be a machine address, either physical or virtual (though
on most implementations it is).
Post by Branimir Maksimovic
http://en.wikipedia.org/wiki/Pointer_%28computing%29
Wikipedia doesn't define what "pointer" means in C; the C standard
does.

Recommended reading: sections 4 (Pointers) and 6 (Arrays and Pointers)
of the comp.lang.c FAQ, <http://www.c-faq.com/>.
--
Keith Thompson (The_Other_Keith) kst-***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Branimir Maksimovic
2010-03-24 19:55:47 UTC
Permalink
On Wed, 24 Mar 2010 11:15:05 -0700
Post by Keith Thompson
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 14:06:28 +0000
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
Since pointer arithmetic in C is identical with
array indexing, plain ints are actually C pointers
with relative addressing ,
No ints are not C pointers they have *very* different
arithmetic rules.
I don;t think so. as *(a+i) is identical to a[i] or i[a]
and a automatically converts to pointer to first element.
Did you know that array subscript is associative?
Commutative, not associative, as you acknowledged in a followup.
Post by Branimir Maksimovic
Do you know why?
Because both pointer+integer and integer+pointer arithmetic are
supported (as well as pointer-integer and pointer-pointer). The
language *could* have required the pointer to appear on the LHS of the
"+", banning integer+pointer. The (unnecessary IMHO) symmetry goes
back to the early days of C, when the distinction between integers and
pointers wasn't as strong as it is now.
Post by Branimir Maksimovic
Only difference is that a+i increments by scale bytes, scale being
type that pointer points to.
Pointer addition is a different operation than integer addition.
Post by Branimir Maksimovic
But C memory model assumes absolute addressing.
Not really, though I suppose it depends on what exactly you mean by
"absolute addressing".
Array indexing in C is relative indexing. Relative pointers are ints,
and absolute pointers are C pointers.
So if you have possibility to declare relative , "near" pointer than
you could do absolute + relative pointer addition .
You can;t add two pointers into C array as they assume absolute
addressing. By that I mean either flat or segmented model.
far/near pointers are necessity, both on flat and segmented model,
since I don;t know CPU that supports only absolute addressing mode.
That means that we have to use int's as pointers into arrays
obtained by malloc and achieve same effect. Actually it's just
a matter of convenient syntax, *(absolutep+relativep)
People just cast ints to pointers for same reason ,but
it is not portable since you have to carry base with it.
And you don;t save memory since it is better to use short
in case you need 64k relative addressing, as relative pointer than C
pointer (because of size). On implementations where short can
be bigger does not matter since it will work anyway.
So actually *++p iteration through array assumes absolute
addressing ,while *(p + relativep) assumes relative addressing.
If I can be more clear.
Post by Keith Thompson
Post by Branimir Maksimovic
You can't do b=a+i;c=a+b;
But you can decrement, since if you substract two absolute addresses
you can;t get out of segment bounds.
That is why it would be useful to have relative /absolute semantics.
Just because to avoid casting ints to pointers in order to
have convenient syntax for array indexing.
I'm not sure what you're saying here, but in some of your other
articles in this thread I think you're conflating two different
things.
I think, malloc guarantees largest segment
and ints are actually relative , short pointers into segment,
while you can still use absolute pointers as bases.
It's just a matter of realizing this.
So for example if you have architecture base+ 12 bit offset like 360
you can't malloc more than 4kb because of absolute+relativep.
Since relativep in this case is 12 bits your size_t is limited to
4096 bytes.
Can someone explain how those things are worked out there?
I worked with 370's but fortran,pascal and cobol in high school and
university. Also Unisys A systems, but cobol. There weren't C compilers.
I wrote T27 emulator and some banking transactions for DOS with it
in C , to support Serbia's electronic payment system ;)
That was back in 92-93.

Greets.
--
http://maxa.homedns.org/

Sometimes online sometimes not
Keith Thompson
2010-03-24 21:04:54 UTC
Permalink
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 11:15:05 -0700
[...]
Post by Branimir Maksimovic
Post by Keith Thompson
Post by Branimir Maksimovic
But C memory model assumes absolute addressing.
Not really, though I suppose it depends on what exactly you mean by
"absolute addressing".
Array indexing in C is relative indexing. Relative pointers are ints,
and absolute pointers are C pointers.
If you're talking about C, it's *very* important to remember that
pointers are not integers, and integers are not pointers.

It's possible to convert between pointer and integer types, but the
result of such a conversion (with the lone exception of converting a
constant 0 to a pointer type) is not portable.
[...]
Post by Branimir Maksimovic
I think, malloc guarantees largest segment
and ints are actually relative , short pointers into segment,
while you can still use absolute pointers as bases.
It's just a matter of realizing this.
Sorry, I don't know what "malloc guarantees largest segment"
is supposed to mean. The C standard, which is what defines the
behavior of malloc, doesn't talk about segments. C is carefully
designed to work on systems with either segmented or monolithic
addressing spaces.
Post by Branimir Maksimovic
So for example if you have architecture base+ 12 bit offset like 360
you can't malloc more than 4kb because of absolute+relativep.
Since relativep in this case is 12 bits your size_t is limited to
4096 bytes.
A conforming hosted C implementation must support objects of at least
65535 bytes (in C99; C90 required 32767 bytes). So size_t must be at
least 16 bits. It's up to the compiler to generate whatever code is
needed to support this.

[...]
--
Keith Thompson (The_Other_Keith) kst-***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Branimir Maksimovic
2010-03-24 22:03:35 UTC
Permalink
On Wed, 24 Mar 2010 14:04:54 -0700
Post by Keith Thompson
If you're talking about C, it's *very* important to remember that
pointers are not integers, and integers are not pointers.
Well digital computer is all numbers. array of 1' and 0's.
Remember, C was meant for assembler programmers.
I first learned basic than assembler on spectrum 48kb.
Then somehow C compiler was available for spectrum,
so when I saw ++ operator, immediately recognized
C as another assembler. Especially was fascinated that
you could crash computer with it same as in assembler.
Technically pointers are integers, but understanding
their meaning and usage on particular implementation
and exploiting it is not portable, of course.
But you *can* do it anyway if necessary and portability
is not of concern.
Post by Keith Thompson
It's possible to convert between pointer and integer types, but the
result of such a conversion (with the lone exception of converting a
constant 0 to a pointer type) is not portable.
[...]
Post by Branimir Maksimovic
I think, malloc guarantees largest segment
and ints are actually relative , short pointers into segment,
while you can still use absolute pointers as bases.
It's just a matter of realizing this.
Sorry, I don't know what "malloc guarantees largest segment"
is supposed to mean. The C standard, which is what defines the
behavior of malloc, doesn't talk about segments. C is carefully
designed to work on systems with either segmented or monolithic
addressing spaces.
Yes but, when you malloc you get chunk of raw memory
that can be indexed by integers of any type.
This maps 1-1 on assembler thinkology ;)
What about memory bank switching model?
Eg on amstrad cpc6128 there was 128kb of ram,
but 8 memory banks of 16kb each.
CPU could address maximum of 64kb.
64kb linear address space for apps and shadow OS
in another 64 kb, CP/M ?
There is *real* C compiler for it.
My second home computer btw ;)
Post by Keith Thompson
Post by Branimir Maksimovic
So for example if you have architecture base+ 12 bit offset like 360
you can't malloc more than 4kb because of absolute+relativep.
Since relativep in this case is 12 bits your size_t is limited to
4096 bytes.
A conforming hosted C implementation must support objects of at least
65535 bytes (in C99; C90 required 32767 bytes). So size_t must be at
least 16 bits. It's up to the compiler to generate whatever code is
needed to support this.
Thanks for explanation.

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Keith Thompson
2010-03-25 00:49:43 UTC
Permalink
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 14:04:54 -0700
Post by Keith Thompson
If you're talking about C, it's *very* important to remember that
pointers are not integers, and integers are not pointers.
Well digital computer is all numbers. array of 1' and 0's.
But that's not all they are. Certain combinations of 1s and 0s have
*meanings*. And we use languages at a higher level than raw binary,
whether assembly language, C, Lisp, or whatever, precisely so we can
manipulate those meaning rather than the 1s and 0s.
Post by Branimir Maksimovic
Remember, C was meant for assembler programmers.
Not really. C is meant for C programmers. Assembler is meant for
assembler programmers.

Yes, C can be an alternative to assembly language, but the whole point
is that it's an alternative. It's not the same thing.
Post by Branimir Maksimovic
I first learned basic than assembler on spectrum 48kb.
Then somehow C compiler was available for spectrum,
so when I saw ++ operator, immediately recognized
C as another assembler.
C's ++ and -- operators were probably inspired by autoincrement and
autodecrement addressing modes on some early PDP-whatever. But
they're much more general.
Post by Branimir Maksimovic
Especially was fascinated that
you could crash computer with it same as in assembler.
Technically pointers are integers, but understanding
their meaning and usage on particular implementation
and exploiting it is not portable, of course.
But you *can* do it anyway if necessary and portability
is not of concern.
Yes, if portability is not a concern, you can do all sorts of ugly
things. You can treat pointers as integers in C, but you have to
fight the language to do it, since C pointers *are not integers*.
Feed the following to a C compiler:
char *p = 0xdeadbeef;
and it will at least complain, and very likely reject your program.

[...]
Post by Branimir Maksimovic
Post by Keith Thompson
Post by Branimir Maksimovic
I think, malloc guarantees largest segment
and ints are actually relative , short pointers into segment,
while you can still use absolute pointers as bases.
It's just a matter of realizing this.
Sorry, I don't know what "malloc guarantees largest segment"
is supposed to mean. The C standard, which is what defines the
behavior of malloc, doesn't talk about segments. C is carefully
designed to work on systems with either segmented or monolithic
addressing spaces.
Yes but, when you malloc you get chunk of raw memory
that can be indexed by integers of any type.
This maps 1-1 on assembler thinkology ;)
Try thinking about C in its own terms. You might find it more
rewarding than forcing it into an assembly-level model.

[snip]
--
Keith Thompson (The_Other_Keith) kst-***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Branimir Maksimovic
2010-03-25 09:39:31 UTC
Permalink
On Wed, 24 Mar 2010 17:49:43 -0700
Post by Keith Thompson
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 14:04:54 -0700
Post by Keith Thompson
If you're talking about C, it's *very* important to remember that
pointers are not integers, and integers are not pointers.
Well digital computer is all numbers. array of 1' and 0's.
But that's not all they are. Certain combinations of 1s and 0s have
*meanings*. And we use languages at a higher level than raw binary,
whether assembly language, C, Lisp, or whatever, precisely so we can
manipulate those meaning rather than the 1s and 0s.
Post by Branimir Maksimovic
Remember, C was meant for assembler programmers.
Not really. C is meant for C programmers. Assembler is meant for
assembler programmers.
Yes, but C programming style is good assembler programming style.
Post by Keith Thompson
Post by Branimir Maksimovic
Especially was fascinated that
you could crash computer with it same as in assembler.
Technically pointers are integers, but understanding
their meaning and usage on particular implementation
and exploiting it is not portable, of course.
But you *can* do it anyway if necessary and portability
is not of concern.
Yes, if portability is not a concern, you can do all sorts of ugly
things. You can treat pointers as integers in C, but you have to
fight the language to do it, since C pointers *are not integers*.
char *p = 0xdeadbeef;
and it will at least complain, and very likely reject your program.
***@maxa:~$ gcc -std=c89 ts.c -o ts
ts.c: In function ‘main’:
ts.c:5: warning: initialization from incompatible pointer type
ts.c:6: warning: initialization makes pointer from integer without a cast
***@maxa:~$
***@maxa:~$ cat ts.c
int main(void)
{
int a=10;
int *pa = &a;
float *p = pa;
float *p1 = 0xdeadbeef;

return 0;
}
***@maxa:~$

That is why C is better than C++. You don;t have to cast in order
to compile such code. But with C you get *warnings* when you
do such things, unlike in C++ (more verbose code, but dangerous code
without warnings)
Casts are actually not necessary. They surve purpose just to shut up
compiler warnings which should be there anyway, for maintenance
programmers or ones that want to *port* code.
Post by Keith Thompson
[...]
Post by Branimir Maksimovic
Post by Keith Thompson
Post by Branimir Maksimovic
I think, malloc guarantees largest segment
and ints are actually relative , short pointers into segment,
while you can still use absolute pointers as bases.
It's just a matter of realizing this.
Sorry, I don't know what "malloc guarantees largest segment"
is supposed to mean. The C standard, which is what defines the
behavior of malloc, doesn't talk about segments. C is carefully
designed to work on systems with either segmented or monolithic
addressing spaces.
Yes but, when you malloc you get chunk of raw memory
that can be indexed by integers of any type.
This maps 1-1 on assembler thinkology ;)
Try thinking about C in its own terms. You might find it more
rewarding than forcing it into an assembly-level model.
I understand, but when you know assembler, C and C++ programs
usually have less bugs regarding classic errors.

Thanks!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Nick Keighley
2010-03-25 09:57:06 UTC
Permalink
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 14:04:54 -0700
Post by Keith Thompson
If you're talking about C, it's *very* important to remember that
pointers are not integers, and integers are not pointers.
Well digital computer is all numbers. array of 1' and 0's.
but is C required to run on such a machine? Intergers, I believe, have
to use a binary representaion. There's no requirement that pointers do
though.
Post by Branimir Maksimovic
Remember, C was meant for assembler programmers.
no it wan't
Post by Branimir Maksimovic
I first learned basic than assembler on spectrum 48kb.
Then somehow C compiler was available for spectrum,
so when I saw ++ operator, immediately recognized
C as another assembler.
and you were mistaken. Assembler maps one-to-one (yes I know about
macro-assemblers) to machine code. C doesn't really do that.
Post by Branimir Maksimovic
Especially was fascinated that
you could crash computer with it same as in assembler.
this makes Windows NT an assembler
Post by Branimir Maksimovic
Technically pointers are integers,
no.
Post by Branimir Maksimovic
but understanding
their meaning and usage on particular implementation
and exploiting it is not portable, of course.
But you *can* do it anyway if necessary and portability
is not of concern.
Post by Keith Thompson
It's possible to convert between pointer and integer types, but the
result of such a conversion (with the lone exception of converting a
constant 0 to a pointer type) is not portable.
Post by Branimir Maksimovic
I think, malloc guarantees largest segment
and ints are actually relative , short pointers into segment,
while you can still use absolute pointers as bases.
It's just a matter of realizing this.
Sorry, I don't know what "malloc guarantees largest segment"
is supposed to mean.  The C standard, which is what defines the
behavior of malloc, doesn't talk about segments.  C is carefully
designed to work on systems with either segmented or monolithic
addressing spaces.
Yes but, when you malloc you get chunk of raw memory
that can be indexed by integers of any type.
This maps 1-1 on assembler thinkology ;)
so Fortran and Java are assembler?

<snip>
Branimir Maksimovic
2010-03-25 10:16:02 UTC
Permalink
On Thu, 25 Mar 2010 02:57:06 -0700 (PDT)
Post by Nick Keighley
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 14:04:54 -0700
Post by Keith Thompson
If you're talking about C, it's *very* important to remember that
pointers are not integers, and integers are not pointers.
Well digital computer is all numbers. array of 1' and 0's.
but is C required to run on such a machine? Intergers, I believe, have
to use a binary representaion. There's no requirement that pointers do
though.
In my terms floats are also integers. I mean digital numbers.
Post by Nick Keighley
Post by Branimir Maksimovic
I first learned basic than assembler on spectrum 48kb.
Then somehow C compiler was available for spectrum,
so when I saw ++ operator, immediately recognized
C as another assembler.
and you were mistaken. Assembler maps one-to-one (yes I know about
macro-assemblers) to machine code. C doesn't really do that.
True, but take for example this code:

***@maxa:~/armjpeg/asmtest$ gcc main.c -o main
***@maxa:~/armjpeg/asmtest$ ./main
bytes 512
0x602040 0x602000
3
5
***@maxa:~/armjpeg/asmtest$

***@maxa:~/armjpeg/asmtest$ cat main.c
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/mman.h>

static char a[8192];

int main()
{
char* p = a + (4096-(size_t)a%4096);
if(mprotect(p,4096, PROT_EXEC | PROT_READ | PROT_WRITE)<0)
{
printf("mprotect %s\n",strerror(errno)); return 0;
}
int fd = open("atest.o",O_RDONLY);
if(fd<0){ printf("%s\n",strerror(errno)); return 0; }
int rc = read(fd,p,4096);
printf("bytes %d\n",rc);
void* (*fp)() = (typeof(fp)) p;
int (*fp1)(float) = (typeof(fp1)) (p+0x10);
memmove(p,p+0x40,1000);
void* b = fp();
/*
int i;

for(i=0;i<4096;++i)
{
if(!memcmp(p+i,"signature",9))break;
}
*/
printf("%p %p\n",b,p);
int k = fp1(5.14);
printf("%d\n",k);
k = fp1(8.14);
printf("%d\n",k);
close(fd);
return 0;
}
***@maxa:~/armjpeg/asmtest$ cat atest.c

static struct {
char sig[24];
int a;
float b;
} table = {"signature atest",5,3.14};

void *getDataAddr()
{
return &table;
}

int asmtest(float b)
{
int bb = table.b;
table.b = b;
return bb;
}
***@maxa:~/armjpeg/asmtest$

You can't do such things easily in other languages.
And yes, segmented model would require more work
to workout this;)
Post by Nick Keighley
Post by Branimir Maksimovic
Especially was fascinated that
you could crash computer with it same as in assembler.
this makes Windows NT an assembler
Windows NT is OS.
Post by Nick Keighley
Post by Branimir Maksimovic
Technically pointers are integers,
no.
Numbers. Ok , I think you all mean by integer mathematical
integer. My meaning for integer is digit, number.
Post by Nick Keighley
Post by Branimir Maksimovic
Yes but, when you malloc you get chunk of raw memory
that can be indexed by integers of any type.
This maps 1-1 on assembler thinkology ;)
so Fortran and Java are assembler?
Nope. I programed fortran iV , different thinking
not like assembler. Java also requires different
thinking.

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Sol-Terrasa mkfs ext4 da' Sussex
2010-03-25 11:16:11 UTC
Permalink
Post by Branimir Maksimovic
bytes 512
0x602040 0x602000
3
5
Causes a segmentation fault on x86 :-D
--
http://www.munted.org.uk

One very high maintenance cat living here.
Nick Keighley
2010-03-25 11:18:41 UTC
Permalink
Post by Branimir Maksimovic
On Thu, 25 Mar 2010 02:57:06 -0700 (PDT)
Post by Nick Keighley
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 14:04:54 -0700
<snip>
Post by Branimir Maksimovic
Post by Nick Keighley
Post by Branimir Maksimovic
I first learned basic than assembler on spectrum 48kb.
Then somehow C compiler was available for spectrum,
so when I saw ++ operator, immediately recognized
C as another assembler.
and you were mistaken. Assembler maps one-to-one (yes I know about
macro-assemblers) to machine code. C doesn't really do that.
the other important thing about assemblers is that they are tied to a
particular machine. Well written C can run on different machines.

<snip>
Post by Branimir Maksimovic
Post by Nick Keighley
Post by Branimir Maksimovic
Especially was fascinated that
you could crash computer with it same as in assembler.
this makes Windows NT an assembler
Windows NT is OS.
if you can crash a computer with it it's an assembler
you can crash a computer with Windows NT
=> Windows NT is an assembler
Post by Branimir Maksimovic
Post by Nick Keighley
Post by Branimir Maksimovic
Technically pointers are integers,
no.
Numbers.
no.
Post by Branimir Maksimovic
Ok , I think you all mean by integer mathematical
integer. My meaning for integer is digit, number.
pointers aren't numbers. Not integers, sureals nor octonions.
Post by Branimir Maksimovic
Post by Nick Keighley
Post by Branimir Maksimovic
Yes but, when you malloc you get chunk of raw memory
that can be indexed by integers of any type.
This maps 1-1 on assembler thinkology ;)
so Fortran and Java are assembler?
Nope. I programed fortran iV , different thinking
not like assembler. Java also requires different
thinking.
we'll just have to agree to disagree
Peter Flass
2010-03-24 21:36:48 UTC
Permalink
Post by Branimir Maksimovic
I think, malloc guarantees largest segment
and ints are actually relative , short pointers into segment,
while you can still use absolute pointers as bases.
It's just a matter of realizing this.
So for example if you have architecture base+ 12 bit offset like 360
you can't malloc more than 4kb because of absolute+relativep.
Since relativep in this case is 12 bits your size_t is limited to
4096 bytes.
This is a false assumption. The displacement in the instruction is 12
bits, but you have an index register that's 2**31 bits, (2GB)
Branimir Maksimovic
2010-03-24 21:41:47 UTC
Permalink
On Wed, 24 Mar 2010 17:36:48 -0400
Post by Peter Flass
Post by Branimir Maksimovic
I think, malloc guarantees largest segment
and ints are actually relative , short pointers into segment,
while you can still use absolute pointers as bases.
It's just a matter of realizing this.
So for example if you have architecture base+ 12 bit offset like 360
you can't malloc more than 4kb because of absolute+relativep.
Since relativep in this case is 12 bits your size_t is limited to
4096 bytes.
This is a false assumption. The displacement in the instruction is
12 bits, but you have an index register that's 2**31 bits, (2GB)
Thanks for explanation.

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
E. S. Fabian
2010-03-24 19:59:39 UTC
Permalink
Keith Thompson wrote:
| For a declared object of any type, ``sizeof object'' yields the size
| in bytes of the object, with a result of type size_t. For an object
| allocated by a call to malloc() the size argument to malloc is of
| type size_t, so it can't create an object bigger than SIZE_MAX bytes.
| (SIZE_MAX, as the name implies, is the largest possible value of
| type size_t.)
|
| Which means that, with the possible exception of some bizarre cases,
| no object can be bigger than SIZE_MAX bytes. Since the elements
| of an array must be at least 1 byte in size, it follows that the
| maximum index for an array object cannot exceed SIZE_MAX.
|
| size_t is the only integer type (other that uintmax_t) that has this
| guarantee.

Actually, byte is not defined in the C standard. It was invented by IBM for 8-bit wide storage locations, but IEEE redefined it as a data element smaller than a word; a series of computers built by Univac for the US Navy actually allowed byte-addressed instructions to specify the size of byte as a field of 1 to 8 bits. Technically, sizeof(object) is the ratio of the size of object and the size of char, thus by definition sizeof(char)=1. A conformant compiler must use at least 8 bits for char (which precludes using the PDP-10 and other machines' instructions for manipulating strings of 7-bit ASCII characters for char data), but there is no upper limit! On many computers with 36b words C is implemented with 9-bit char. OTOH OW compilers do define char to be 8 bits, regardless of host or target, since all its host and target computers use register sizes compatible with 8b, 16b, 32b, and 64b integers. However, a pointer may also be 48 bits (16:32)...

| Recommended reading: sections 4 (Pointers) and 6 (Arrays and
| Pointers) of the comp.lang.c FAQ, <http://www.c-faq.com/>.

Interesting loose interpretation of the standard.
Hans-Bernhard Bröker
2010-03-24 21:06:11 UTC
Permalink
Actually, */byte/* is not defined in the C standard.
Actually, it quite definitely _is_. The definition even has a section
number all to itself: 3.6.
Nick Keighley
2010-03-25 09:20:50 UTC
Permalink
Post by Keith Thompson
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 14:06:28 +0000
<snip>
Post by Keith Thompson
Post by Branimir Maksimovic
       No ints are not C pointers they have *very* different
arithmetic rules.
I don;t think so. as *(a+i) is identical to a[i] or i[a]
and a automatically converts to pointer to first element.
Did you know that array subscript is [commutative]?
[...]
Post by Keith Thompson
Post by Branimir Maksimovic
Do you know why?
because Dennis said so
Post by Keith Thompson
Because both pointer+integer and integer+pointer arithmetic are
supported (as well as pointer-integer and pointer-pointer).  The
language *could* have required the pointer to appear on the LHS of the
"+", banning integer+pointer.  The (unnecessary IMHO) symmetry goes
back to the early days of C, when the distinction between integers and
pointers wasn't as strong as it is now.
Post by Branimir Maksimovic
Only difference is that a+i increments by scale bytes, scale being
type that pointer points to.
Pointer addition is a different operation than integer addition.
Post by Branimir Maksimovic
But C memory model assumes absolute addressing.
Not really, though I suppose it depends on what exactly you mean by
"absolute addressing".
I can't begin to guess what it means, but I'm pretty sure it's wrong.
Post by Keith Thompson
Post by Branimir Maksimovic
You can't do b=a+i;c=a+b;
But you can decrement, since if you substract two absolute addresses
you can;t get out of segment bounds.
That is why it would be useful to have relative /absolute semantics.
Just because to avoid casting ints to pointers in order to
have convenient syntax for array indexing.
I'm not sure what you're saying here, but in some of your other
articles in this thread I think you're conflating two different
things.
C requires all pointers of a given type to have the same size and
representation.  char* and int* might be different, but any two
pointers to char are stored the same way.  On some systems, it might
be convenient to be able to have different "flavors" of pointers to
the same type, where the different flavors might, for example, be able to
point to different regions of memory.  On a 64-bit system, you might
want to have 64-bit pointers that can point anywhere, and 32-bit
pointers that can only point into the bottom 4GB of memory.
C doesn't support this.  Pointers are distinguished only by the type
they point to.  If I obtain a pointer to an int object, I can copy
that pointer value into any other pointer-to-int object and
dereference the copy without knowing or caring how the original
pointer was generated.
This kind of thing can be supported by an implementation-specific
extension, such as the "near" and "far" pointer types in some x86
compilers.  But any code that uses such an extension is non-portable.
On the other hand, C does *not* assume a monolithic addressing space.
If anything it assumes a segmented address space with every object in
its own segment. Not sure about sub-objects tho
Post by Keith Thompson
A C pointer might internally consist of a segment identifier plus
an offset into that segment.  Pointer arithmetic might affect only
the offset.
<snip>
Phil Carmody
2010-03-24 23:22:45 UTC
Permalink
f/u set.
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 14:45:24 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 12:41:04 +0000
Post by Ahem A Rivet's Shot
Only if they're big enough - nothing prevents a C
implementation having no integer type bigger than 32 bits while
pointers are (say) 48 bits.
Problem is that integers are used to index into arrays.
Well strictly speaking you need size_t in order to guarantee being
able to index into any array.
Post by Branimir Maksimovic
Since arrays are identical to raw memory segment thanks to malloc,
Nothing guarantees that.
Nothing even _defines_ what that means. 'Raw' and 'segment' have
simply been pulled out of an over-active imagination.
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
ints must have capability to index maximum array/segment
size on architecture. So actually long long would be
enough big for maximum relative indexing of segment.
Nope size_t must be big enough for that, but there's no requirement
that any int type be as big as size_t.
How else can there be a corresponding signed type? (n869 7.19.6.1)
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
Since pointer arithmetic in C is identical with
array indexing, plain ints are actually C pointers
with relative addressing ,
No ints are not C pointers they have *very* different arithmetic
rules.
Post by Branimir Maksimovic
while you p[revious explanation
shows that ordinary C pointers are actually absolute addressing
pointers with convenient syntax.
Actually implementation can identify any pointer with
int as they are identical to indexes into arrays,
but void* and char* has to be absolute addresses.
Pointers do not have to be any kind of address.
The pointer which is a result of the & operator has to be a very
addressy kind of address.

Phil
--
I find the easiest thing to do is to k/f myself and just troll away
-- David Melville on r.a.s.f1
Nick Keighley
2010-03-25 08:51:43 UTC
Permalink
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 12:41:04 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 12:48:26 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 11:16:06 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 10:57:37 +0100
<snip>
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
If this is allowed then yes, C and C++ does not assume
flat memory model.
 It doesn't - all that C requires of pointers is that they
can be dereferenced, converted to void pointers and back again,
and that adding and subtracting integers works within certain
well defined limits. Nothing requires them to be machine
addresses.
Hm , how abstract C and C++ machine looks like? Is it flat
address space or segmented?
   What abstract machine ?
What this mister is talking about then?
http://www.stanford.edu/group/sequoia/cgi-bin/node/15
he's talking nonsense. He's really trying to talk about some tree-like
memory model and contrasts it with some flat memory model he chooses
to call the "C abstract memory model". This actually doesn't have
anything to do with C's memory model. The stuff about registers
doesn't even parse.

On the other hand the C standard does talk about an abstract machine.
"The semantic descriptions in this standard describe the behavior of
an abstract machine..."

<snip>


--
SICP is the most important printed literature to develop
from our species in the 20th century.
(Amazon Review)
jmfbahciv
2010-03-25 13:31:07 UTC
Permalink
Post by Nick Keighley
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 12:41:04 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 12:48:26 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 11:16:06 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 10:57:37 +0100
<snip>
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
If this is allowed then yes, C and C++ does not assume
flat memory model.
It doesn't - all that C requires of pointers is that they
can be dereferenced, converted to void pointers and back again,
and that adding and subtracting integers works within certain
well defined limits. Nothing requires them to be machine
addresses.
Hm , how abstract C and C++ machine looks like? Is it flat
address space or segmented?
What abstract machine ?
What this mister is talking about then?
http://www.stanford.edu/group/sequoia/cgi-bin/node/15
he's talking nonsense. He's really trying to talk about some tree-like
memory model and contrasts it with some flat memory model he chooses
to call the "C abstract memory model". This actually doesn't have
anything to do with C's memory model. The stuff about registers
doesn't even parse.
On the other hand the C standard does talk about an abstract machine.
"The semantic descriptions in this standard describe the behavior of
an abstract machine..."
<snip>
It sounds like he believes that everything has to be in core and
physically addressable at all times. No virtual addressing is
allowed and certainly no swapping nor disk buffers.

/BAH
Branimir Maksimovic
2010-03-25 13:33:27 UTC
Permalink
On Thu, 25 Mar 2010 08:31:07 -0500
Post by jmfbahciv
Post by Nick Keighley
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 12:41:04 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 12:48:26 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 11:16:06 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 10:57:37 +0100
<snip>
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
If this is allowed then yes, C and C++ does not assume
flat memory model.
It doesn't - all that C requires of pointers is that they
can be dereferenced, converted to void pointers and back again,
and that adding and subtracting integers works within certain
well defined limits. Nothing requires them to be machine
addresses.
Hm , how abstract C and C++ machine looks like? Is it flat
address space or segmented?
What abstract machine ?
What this mister is talking about then?
http://www.stanford.edu/group/sequoia/cgi-bin/node/15
he's talking nonsense. He's really trying to talk about some
tree-like memory model and contrasts it with some flat memory model
he chooses to call the "C abstract memory model". This actually
doesn't have anything to do with C's memory model. The stuff about
registers doesn't even parse.
On the other hand the C standard does talk about an abstract
machine. "The semantic descriptions in this standard describe the
behavior of an abstract machine..."
<snip>
It sounds like he believes that everything has to be in core and
physically addressable at all times. No virtual addressing is
allowed and certainly no swapping nor disk buffers.
/BAH
It sounds he is talking from application programmer perspective.
Such hardware certainly is possible as front side bus really lags
behind clock. Memory is not problem but cpu BUS.
So for example on architecture that you can explicitelly control
CPU cache memory (and it is very BIG in megabytes) L1 cache
is 8kb and more usually, (people use to place whole flight simulator in
zx81 1kb of ram). You got the picture. When you ca nplace your code
and data in cache , you program would run about 10-30 times faster
on same CPU.
But I don;t think that C would have any difficulties whith this.

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
jmfbahciv
2010-03-25 14:22:13 UTC
Permalink
Post by Branimir Maksimovic
On Thu, 25 Mar 2010 08:31:07 -0500
Post by jmfbahciv
Post by Nick Keighley
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 12:41:04 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 12:48:26 +0100
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 11:16:06 +0000
Post by Ahem A Rivet's Shot
On Wed, 24 Mar 2010 10:57:37 +0100
<snip>
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
Post by Ahem A Rivet's Shot
Post by Branimir Maksimovic
If this is allowed then yes, C and C++ does not assume
flat memory model.
It doesn't - all that C requires of pointers is that they
can be dereferenced, converted to void pointers and back again,
and that adding and subtracting integers works within certain
well defined limits. Nothing requires them to be machine
addresses.
Hm , how abstract C and C++ machine looks like? Is it flat
address space or segmented?
What abstract machine ?
What this mister is talking about then?
http://www.stanford.edu/group/sequoia/cgi-bin/node/15
he's talking nonsense. He's really trying to talk about some
tree-like memory model and contrasts it with some flat memory model
he chooses to call the "C abstract memory model". This actually
doesn't have anything to do with C's memory model. The stuff about
registers doesn't even parse.
On the other hand the C standard does talk about an abstract
machine. "The semantic descriptions in this standard describe the
behavior of an abstract machine..."
<snip>
It sounds like he believes that everything has to be in core and
physically addressable at all times. No virtual addressing is
allowed and certainly no swapping nor disk buffers.
/BAH
It sounds he is talking from application programmer perspective.
It doesn't matter. He has the attitude that all the eggs have
to be in the frying pan whenever he wants to eat one.
Post by Branimir Maksimovic
Such hardware certainly is possible as front side bus really lags
behind clock. Memory is not problem but cpu BUS.
So for example on architecture that you can explicitelly control
CPU cache memory (and it is very BIG in megabytes) L1 cache
is 8kb and more usually, (people use to place whole flight simulator in
zx81 1kb of ram). You got the picture. When you ca nplace your code
and data in cache , you program would run about 10-30 times faster
on same CPU.
Only if it's CPU-bound, does absolutely no I/O (including terminal
I/O) and probably no comm.
Post by Branimir Maksimovic
But I don;t think that C would have any difficulties whith this.
That all depends on how the code is coded. It has nothing to
do with C nor any other language nor machine code.

/BAH
Peter Flass
2010-03-24 10:51:09 UTC
Permalink
Post by Richard Bos
Post by Peter Flass
Post by Branimir Maksimovic
Problem with standard C and C++ is that they assume flat memory
model.
Nonsense.
Post by Peter Flass
I'm not a C expert, perhaps you're a denizen of comp.lang.c, but as far
as I know there's nothing in the C standard that assumes anything about
pointers, except that they have to be the same size as int,
There is absolutely nothing in the C Standard that requires pointers to
have the size of int, or even the size of anything whatsoever, except
that
- void pointers and char pointers shall have the same representation
(and therefore size) as one another - _not_ necessarily as any other
kind of pointer, though since void pointers must be able to be freely
convertible from and to other object pointers, it takes a perverted
implementation to make them _smaller_ than other object pointers (but
perversion, though not advised, is allowed implementation authors);
- pointers to const <foo> must have the same representation as pointers
to <foo> and vice versa, and ditto for volatile and restrict;
- all pointers to struct must have the same representation, and all
pointers to union (but struct pointers need not be the same as union
pointers; again, it would usually be silly not to have them be, but
it's allowed).
Nothing about ints there.
Yes, I've gotten a few corrections on this;-) I guess what I was
thinking of is a statement I've heard several times that lots of
existing C code *assumes* sizeof(ptr) = sizeof(int), and breaks when
this isn't true.
Branimir Maksimovic
2010-03-24 10:57:58 UTC
Permalink
On Wed, 24 Mar 2010 06:51:09 -0400
Post by Peter Flass
Post by Richard Bos
Nothing about ints there.
Yes, I've gotten a few corrections on this;-) I guess what I was
thinking of is a statement I've heard several times that lots of
existing C code *assumes* sizeof(ptr) = sizeof(int), and breaks when
this isn't true.
It is strange that one have to check for size of pointer, because
you can always implement segmented/relative addressing model,
buy using shorts/ints/longs/longlongs as pointers
into array(segment) and implement far near pointer thing,
without problem thanks to malloc and brilliant design
of C arrays that can map to 1-1 to real segment.
Technically besides void* (as a base) there is no real use of any
other type of C or C++ pointer in portable code.
Ints would do perfectly. No need to check for sizes of pointers
at all ;)

Greets
--
http://maxa.homedns.org/

Sometimes online sometimes not
E. S. Fabian
2010-03-24 13:09:27 UTC
Permalink
Peter Flass wrote:
| Yes, I've gotten a few corrections on this;-) I guess what I was
| thinking of is a statement I've heard several times that lots of
| existing C code *assumes* sizeof(ptr) = sizeof(int), and breaks when
| this isn't true.

GIGO: garbage input (invalid source code to compiler) -> garbage output
(miscompiled program).

There are a number of common assumptions unthinking programmers make that
are not based on the standard, but on some specific compiler's behavior.
E.g., sizeof(int)=sizeof(short), which is typically true on Intel
architecture for so-called "16-bit" programs, or sizeof(int)=sizeof(long),
which is typically true on Intel architecture for so-called "32-bit"
programs.

One of the major problems with the Intel-related terms "16-bit", "32-bit",
and "64-bit" is that unlike other vendors' architectures, Intel makes the
widths of the storage data bus, of the storage address bus, and of the
arithmetic unit integer register identical (with a few, early exceptions,
e.g., 8088). Other manufacturers make use of the logical independence of
those sizes for such things as reduced component manufacturing cost,
machines scalable to your budget without software change, etc. It is a
travesty that some OS vendors' newer OS versions do not support older
programs that were written for some of their own prior OS versions, and
which the hardware fully supports.

The term POINTER is used in the C standard explicitly to avoid specifying
THE method of dereferencing (translating pointer to storage location), and
it is up to the compiler to implement pointer processing that fits the
target hardware. When the hardware offers many different methods of
translation, the compiler may choose one of them for all occasions, or it
may use any mix of all methods that yield a correct mapping of the code for
each source statement.

Enough now for what's basically OT.
--
Steve
Jonathan de Boyne Pollard
2010-03-25 02:44:35 UTC
Permalink
Post by E. S. Fabian
One of the major problems with the Intel-related terms "16-bit",
"32-bit", and "64-bit" is that unlike other vendors' architectures,
Intel makes the widths of the storage data bus, of the storage address
bus, and of the arithmetic unit integer register identical (with a
few, early exceptions, e.g., 8088). Other manufacturers make use of
the logical independence of those sizes for such things as reduced
component manufacturing cost, machines scalable to your budget without
software change, etc. It is a travesty that some OS vendors' newer OS
versions do not support older programs that were written for some of
their own prior OS versions, and which the hardware fully supports.
Which processor architecture are you implying those operating systems
run on? Intel? Or the "other manufacturers'"?
Jonathan de Boyne Pollard
2010-03-23 17:18:21 UTC
Permalink
Post by Peter Flass
Post by Jonathan de Boyne Pollard
Returning to what we were talking about before the silly diversion, I
should point out that 32-bit applications programming where the
target is extended DOS or 32-bit Win16 (with OpenWatcom's extender)
will also occasionally employ 16:32 far pointers of course. But as I
said before, regular 32-bit OS/2 or Win32 applications programming
generally does not, since those both use the Tiny memory model, [...]
Flat memory model.
It's the same thing. Think about it. In the flat memory model
DS=ES=SS=CS (modulo the various required differences between code and
data segment descriptors) and all pointers are near. That's the
definition of the tiny memory model. The flat memory model is the tiny
memory model.

Since we are discussing OpenWatcom, I point to the OpenWatcom Users
Guide as one place where you can see this for yourself quite easily. In
the 16-bit Memory Models section, you'll find a Summary of 16-bit Memory
Models subsection, with a table. In the 32-bit Memory Models section,
you'll find a Summary of 32-bit Memory Models subsection, with a table.
Compare the tables in the twain, and you'll see that the row labelled
"tiny" in the former is labelled "flat" in the latter.

There's no real distinction between the twain (apart from some
implementation-specific pre-defined macros). 32-bit flat model
programming is 32-bit tiny model programming, and 16-bit tiny model
programming is 16-bit flat model programming. In all, near pointers to
automatic storage data, heap storage data, static storage data, and code
can be casted to one another without differences in assumed segment
registers causing problems. In all, the code generator doesn't emit
segment re-loads, or even segment overrides, when using the default
pointer sizes. In all, near forms of instructions are used.
Nick
2010-03-23 18:49:33 UTC
Permalink
Jonathan de Boyne Pollard <J.deBoynePollard-***@NTLWorld.COM>
writes:

PLEASE! Don't cut all the attributions. I've seen you asked this more
than once in a different newsgroup in the last few days and you've
ignored the requests. Please listen to them.
[content snipped]
--
Online waterways route planner | http://canalplan.eu
Plan trips, see photos, check facilities | http://canalplan.org.uk
jmfbahciv
2010-03-24 12:24:12 UTC
Permalink
Post by Nick
PLEASE! Don't cut all the attributions. I've seen you asked this more
than once in a different newsgroup in the last few days and you've
ignored the requests. Please listen to them.
[content snipped]
I've stopped reading what he writes because he's snipped the context.

/BAH
r***@yahoo.com
2010-03-23 19:42:24 UTC
Permalink
On Mar 23, 12:18 pm, Jonathan de Boyne Pollard <J.deBoynePollard-
Post by Peter Flass
Post by Jonathan de Boyne Pollard
Returning to what we were talking about before the silly diversion, I
should point out that 32-bit applications programming where the
target is extended DOS or 32-bit Win16 (with OpenWatcom's extender)
will also occasionally employ 16:32 far pointers of course.  But as I
said before, regular 32-bit OS/2 or Win32 applications programming
generally does not, since those both use the Tiny memory model, [...]
Flat memory model.
It's the same thing.  Think about it.  In the flat memory model
DS=ES=SS=CS (modulo the various required differences between code and
data segment descriptors) and all pointers are near.  That's the
definition of the tiny memory model.  The flat memory model is the tiny
memory model.
Just to be pedantic, while DS==ES==SS (IOW, they contain exactly the
same selector), CS contains a *different* selector than the other
three segment registers in flat model. The descriptor for the CS
selector specifies the same base address and limit (usually), and thus
overlaps the data descriptor referenced by the other segment
registers, so all of them address the same memory. But they are not
interchangeable - while you could load the code selector into DS, an
attempt to store data would then generate an exception. Conversely
attempting to load a data selector into CS will trigger an exception.

This is different from the real-mode "tiny" model, where CS would be
loaded with the same segment value as DS, ES and SS. So I’d have to
say that using “tiny model” to mean “flat model” is at least slightly
incorrect.
Branimir Maksimovic
2010-03-23 19:55:17 UTC
Permalink
On Tue, 23 Mar 2010 12:42:24 -0700 (PDT)
Post by r***@yahoo.com
On Mar 23, 12:18 pm, Jonathan de Boyne Pollard <J.deBoynePollard-
Post by Peter Flass
Post by Jonathan de Boyne Pollard
Returning to what we were talking about before the silly
diversion, I should point out that 32-bit applications
programming where the target is extended DOS or 32-bit Win16
(with OpenWatcom's extender) will also occasionally employ 16:32
far pointers of course.  But as I said before, regular 32-bit
OS/2 or Win32 applications programming generally does not, since
those both use the Tiny memory model, [...]
Flat memory model.
It's the same thing.  Think about it.  In the flat memory model
DS=ES=SS=CS (modulo the various required differences between code
and data segment descriptors) and all pointers are near.  That's the
definition of the tiny memory model.  The flat memory model is the
tiny memory model.
Just to be pedantic, while DS==ES==SS (IOW, they contain exactly the
same selector), CS contains a *different* selector than the other
three segment registers in flat model. The descriptor for the CS
selector specifies the same base address and limit (usually), and thus
overlaps the data descriptor referenced by the other segment
registers, so all of them address the same memory. But they are not
interchangeable - while you could load the code selector into DS, an
attempt to store data would then generate an exception. Conversely
attempting to load a data selector into CS will trigger an exception.
Hm , I think that protection mechanism id done on page level rather
on segment level. JIT couldn;t be possible in case of whole CS
segment is marked as read/execute only.
JIT could have to hack into more privileged level in order to perform
writes/instruction cache flush/execute.

Greets
--
http://maxa.homedns.org/

Sometimes online sometimes not
Jonathan de Boyne Pollard
2010-03-23 22:06:22 UTC
Permalink
Post by r***@yahoo.com
Post by Jonathan de Boyne Pollard
It's the same thing. Think about it. In the flat memory model
DS=ES=SS=CS (modulo the various required differences between code and
data segment descriptors) and all pointers are near. That's the
definition of the tiny memory model. The flat memory model is the
tiny memory model.
Just to be pedantic, while DS==ES==SS (IOW, they contain exactly the
same selector), CS contains a *different* selector than the other
three segment registers in flat model. [...]
That's not being pedantic. That's simply ignoring what I put in the
parentheses. It's also commits the common "just to be pedantic" error
of being outright wrong if one really were being pedantic. (-: If you
look at what an x86 processor actually does with the segment descriptor
cache in real and v8086 modes, you'll see that in fact there are
differences between CS on the one hand and DS/ES/SS on the other in
real/v8086 mode, which you are incorrectly asserting to be the sole
domain of the tiny model, just as there are differences between the two
in protected mode, which you are incorrectly asserting to be the sole
domain of the flat model. Both real/v8086 and protected modes make this
distinction, and this is not, therefore, something that distinguishes
the flat model from the tiny model. Processor execution modes and
program memory models are largely disjoint concepts.

There are plenty of articles by Robert R. Collins in Dr Dobbs' Journal
from the late 1990s on this subject that one can read for onesself,
which I'm not going to laboriously re-hash. A breif précis only then:
Whilst the documentation may suggest that the descriptor cache is
ignored in real and v8086 modes, the reality is that in real and v8086
modes the segment descriptors are still re-loaded with appropriate
(hardwired) values upon a re-load of any segment register, and the
values in the descriptor registers are not wholly ignored but are in
fact still used by the address calculation hardware. The idea that the
CS segment descriptor is the same as the DS/ES/SS segment descriptors in
the tiny model, because only the selector register values themselves
count in real/v8086 modes, is thus a falsehood. The segment descriptors
have effect in all three of real, v8086, and protected modes. Moreover,
this effect has much the same split in real/v8086 modes as in protected
mode. There's special-case processing for the CS segment descriptor in
real/v8086 modes that differentiates it from the DS/ES/SS segment
descriptors. The supposed lack of distinction amongst or use of segment
descriptors, that makes flat model a protected-mode-only thing and tiny
model a real/v8086-mode-only thing, is bogus. Read Robert R. Collins'
articles for a lot more on this.

As I said before, the two are, in reality, only really distinguished by
some pre-defined macros. Those macros aside, the C/C++ language pointer
semantics that one sees, with all pointers being near pointers, the
things that the code generator does, with no selector re-loads or
segment register overrides employed, and the instruction forms used,
with all instructions using their near address forms, are the same for
both flat and tiny models.
r***@yahoo.com
2010-03-24 05:56:53 UTC
Permalink
On Mar 23, 5:06 pm, Jonathan de Boyne Pollard <J.deBoynePollard-
Post by r***@yahoo.com
It's the same thing.  Think about it.  In the flat memory model
DS=ES=SS=CS (modulo the various required differences between code and
data segment descriptors) and all pointers are near.  That's the
definition of the tiny memory model.  The flat memory model is the
tiny memory model.
Just to be pedantic, while DS==ES==SS (IOW, they contain exactly the
same selector), CS contains a *different* selector than the other
three segment registers in flat model. [...]
That's not being pedantic.  That's simply ignoring what I put in the
parentheses.  It's also commits the common "just to be pedantic" error
of being outright wrong if one really were being pedantic.  (-:  If you
look at what an x86 processor actually does with the segment descriptor
cache in real and v8086 modes, you'll see that in fact there are
differences between CS on the one hand and DS/ES/SS on the other in
real/v8086 mode, which you are incorrectly asserting to be the sole
domain of the tiny model, just as there are differences between the two
in protected mode, which you are incorrectly asserting to be the sole
domain of the flat model.  Both real/v8086 and protected modes make this
distinction, and this is not, therefore, something that distinguishes
the flat model from the tiny model.  Processor execution modes and
program memory models are largely disjoint concepts.
OK, to quote you: "In the flat memory model DS=ES=SS=CS (modulo the
various required differences between code and data segment
descriptors) and all pointers are near." The last part is certainly
true ("all pointers are near"), and the parenthetical is reasonably
correct (the code descriptor must be somewhat different than the data
descriptor). The pedantic correction has to do with the assertion
"DS=ES=SS=CS". Without additional comment this is manifestly untrue
in flat model, as you could execute the following code:

mov ax,ds
mov bx,cs
cmp ax,bx

and the Z flag will *not* be set. The contents of those registers
are, to a resonable extent (at least so long as the program avoid
trying to store via CS) *logically* equivilent, but certainly they are
not equal. And equality is what is specified by the chosen operators
in "DS=ES=SS=CS". Practical difficulties aside (as in it's not an
ASCII character), the triple-bar equivalence symbol would certainly
make *your* meaning clear, but you simply can't assume that as the
default interpretation of "=".

The correction is also pedantic (in the common sense of minutia)
because most flat model application never attempt to store through CS,
and never actually inspect or modify the values in the segment
registers, so for them there is no practical difference between
equality and equivalence.

In real mode, ignoring some of the odder effect possible from getting
unusual values loaded into the descriptor cache, the values in the
segment register *are* equal (and also logically equivalent, but
that's trivial).


(...true but irrelevant stuff about descriptor cache operation
snipped...)
As I said before, the two are, in reality, only really distinguished by
some pre-defined macros.  Those macros aside, the C/C++ language pointer
semantics that one sees, with all pointers being near pointers, the
things that the code generator does, with no selector re-loads or
segment register overrides employed, and the instruction forms used,
with all instructions using their near address forms, are the same for
both flat and tiny models.
I never disagreed with any of that.
Wilton Helm
2010-03-24 16:12:53 UTC
Permalink
Another practical difference is that in the tiny model, accessible memory is
given up for program efficiency. In the flat model the registers are large
enough that this trade-off is not require. Of course, the result is bulkier
code and data because everything has to support that larger register size.

Wilton
Jonathan de Boyne Pollard
2010-03-25 01:23:30 UTC
Permalink
Post by Wilton Helm
Another practical difference is that in the tiny model, accessible
memory is given up for program efficiency. In the flat model the
registers are large enough that this trade-off is not require.
Bogus argument. You're assuming a difference as a premise, and then
using that premise to prove that there's a difference. This is really
very simple: There is no real difference (apart from those pre-defined
macros). Your assumed premise is bogus. Memory models don't imply
processor execution modes, nor do they imply either target platforms or
bitness. (The large memory model, for comparison, is still the large
memory model whether the bitness of the pointers is 16:16 because one is
using wcc/wpp or 16:32 because one is using wcc386/wpp386.) They are
largely disjoint from those concepts. Whether flat or tiny, the
compiler does not emit code any differently, the programmer sees the
same near pointers, and the instructions generated are all near form.
(As just pointed out to M. Person, the actual C and C++ compilers
themselves in OpenWatcom C/C++ don't even know about these memory models
as distinct models in their own rights, throwing the information about
-mf away once some pre-defined macros have been set up, and not even
recognizing -mt at all.) Flat model and tiny model are in reality but
two names for the same thing.
Paul S. Person
2010-03-24 17:52:34 UTC
Permalink
On Tue, 23 Mar 2010 17:18:21 +0000, Jonathan de Boyne Pollard
<J.deBoynePollard-***@NTLWorld.COM> wrote:

<snippo -- and reduced to openwatcom.users.c_cpp!>
Post by Jonathan de Boyne Pollard
Since we are discussing OpenWatcom, I point to the OpenWatcom Users
Guide as one place where you can see this for yourself quite easily. In
the 16-bit Memory Models section, you'll find a Summary of 16-bit Memory
Models subsection, with a table. In the 32-bit Memory Models section,
you'll find a Summary of 32-bit Memory Models subsection, with a table.
Compare the tables in the twain, and you'll see that the row labelled
"tiny" in the former is labelled "flat" in the latter.
Since we are discussing Open Watcom, and since Open Watcom clearly
distinguishes between "tiny" and "flat", I suggest that we should do
the same.

I agree that they are pretty much the same in that everything, data
plus code, is placed in a single segment. Others have pointed out,
however, that code and data use different selectors in flat model. It
is also worth keeping in mind that "tiny" really is /tiny/ -- the
single segment is 64K bytes. "flat", on the other hand, uses a much
much larger segment. Indeed, I would consider a 32-bit program (not an
OS, who knows what that might need) that cannot be done in "flat" to
be a monster.
--
"Nature must be explained in
her own terms through
the experience of our senses."
Richard Bos
2010-03-23 19:15:43 UTC
Permalink
Post by Ian Collins
Please stop this asinine cross posting.
That crossposting was, for once, not asinine. It served as a nice
example why, even now, Leenux weenies are not correct when they insist
that C has a flat memory model and all pointers are just numbers.

Richard
glen herrmannsfeldt
2010-03-23 20:56:21 UTC
Permalink
In alt.sys.pdp10 Richard Bos <***@xs4all.nl> wrote:
(snip)
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a nice
example why, even now, Leenux weenies are not correct when they insist
that C has a flat memory model and all pointers are just numbers.
Well, you could also read the C standard to learn that.

There are additional complications for C on the PDP-10.

-- glen
Nick Keighley
2010-03-24 08:53:56 UTC
Permalink
Post by glen herrmannsfeldt
(snip)
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a nice
example why, even now, Leenux weenies are not correct when they insist
that C has a flat memory model and all pointers are just numbers.
Well, you could also read the C standard to learn that.
but if you say that you get accused of language lawyering.
"Since IBM stopped making 360s no C program ever needs to run on such
a platform"
Post by glen herrmannsfeldt
There are additional complications for C on the PDP-10.
Dann Corbit
2010-03-24 09:39:34 UTC
Permalink
In article <1e27d5ee-a1b1-45d9-9188-
Post by Nick Keighley
Post by glen herrmannsfeldt
(snip)
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a nice
example why, even now, Leenux weenies are not correct when they insist
that C has a flat memory model and all pointers are just numbers.
Well, you could also read the C standard to learn that.
but if you say that you get accused of language lawyering.
"Since IBM stopped making 360s no C program ever needs to run on such
a platform"
We have customers who are running their business on harware from the mid
1980s. It may sound ludicrous, but it if solves all of their business
needs, and runs solid 24x365, why should they upgrade?
Post by Nick Keighley
Post by glen herrmannsfeldt
There are additional complications for C on the PDP-10.
Nick Keighley
2010-03-24 11:47:43 UTC
Permalink
Post by Dann Corbit
In article <1e27d5ee-a1b1-45d9-9188-
Post by Nick Keighley
Post by glen herrmannsfeldt
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a nice
example why, even now, Leenux weenies are not correct when they insist
that C has a flat memory model and all pointers are just numbers.
Well, you could also read the C standard to learn that.
but if you say that you get accused of language lawyering.
"Since IBM stopped making 360s no C program ever needs to run on such
a platform"
We have customers who are running their business on harware from the mid
1980s.  It may sound ludicrous, but it if solves all of their business
needs, and runs solid 24x365, why should they upgrade?
why did I scare quote it?

<snip>
Walter Bushell
2010-03-24 15:14:11 UTC
Permalink
Post by Dann Corbit
In article <1e27d5ee-a1b1-45d9-9188-
(snip)
Post by Dann Corbit
We have customers who are running their business on harware from the mid
1980s. It may sound ludicrous, but it if solves all of their business
needs, and runs solid 24x365, why should they upgrade?
<snip>

None, except one should have a backup plan for when the hardware fails.
New development should be done on modern platforms.
--
A computer without Microsoft is like a chocolate cake without mustard.
Phil Carmody
2010-03-24 23:40:10 UTC
Permalink
Post by Dann Corbit
In article <1e27d5ee-a1b1-45d9-9188-
Post by Nick Keighley
Post by glen herrmannsfeldt
(snip)
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a nice
example why, even now, Leenux weenies are not correct when they insist
that C has a flat memory model and all pointers are just numbers.
Well, you could also read the C standard to learn that.
but if you say that you get accused of language lawyering.
"Since IBM stopped making 360s no C program ever needs to run on such
a platform"
We have customers who are running their business on harware from the mid
1980s. It may sound ludicrous, but it if solves all of their business
needs, and runs solid 24x365, why should they upgrade?
Because they could run an equivalently computationally powerful
solution with various levels of redundancy and fail-over protection,
with a power budget sensibly measured in mere Watts?

Phil, who has customers who prefer systems consuming <20 mW.
--
I find the easiest thing to do is to k/f myself and just troll away
-- David Melville on r.a.s.f1
Nick Keighley
2010-03-25 10:02:51 UTC
Permalink
Post by Phil Carmody
Post by Dann Corbit
In article <1e27d5ee-a1b1-45d9-9188-
Post by Nick Keighley
Post by glen herrmannsfeldt
(snip)
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a nice
example why, even now, Leenux weenies are not correct when they insist
that C has a flat memory model and all pointers are just numbers.
Well, you could also read the C standard to learn that.
but if you say that you get accused of language lawyering.
"Since IBM stopped making 360s no C program ever needs to run on such
a platform"
We have customers who are running their business on harware from the mid
1980s.  It may sound ludicrous, but it if solves all of their business
needs, and runs solid 24x365, why should they upgrade?
Because they could run an equivalently computationally powerful
solution with various levels of redundancy and fail-over protection,
with a power budget sensibly measured in mere Watts?
does it have a Coral compiler?
Branimir Maksimovic
2010-03-24 10:18:07 UTC
Permalink
On Wed, 24 Mar 2010 01:53:56 -0700 (PDT)
Post by Nick Keighley
Post by glen herrmannsfeldt
(snip)
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a nice
example why, even now, Leenux weenies are not correct when they
insist that C has a flat memory model and all pointers are just
numbers.
Well, you could also read the C standard to learn that.
but if you say that you get accused of language lawyering.
"Since IBM stopped making 360s no C program ever needs to run on such
a platform"
Problem is that segmented memory model is much better when working
with 64 bit address space. Flat memory model wastes to much
RAM. It would be better for standard C and C++ to provide appropriate
pointer semantics in order to keep memory usage optimal.
What is use of 64 bit flat pointers when you can actually
just load segment base and work with offsets?
Actually compilers are forced to use maximum possible
size of pointer in order to cover all possible sizes,
because of memory model forced by C and C++.
This is not about segmented flat model.
It is about different addressing modes even in flat model.
It seems that besides flat memory model C and C++ assumes
always absolute addressing pointers.
Technically this limitation can be easily circumvented
if different sizes of pointers to same type are allowed.
Ok, void* should be maximum size, but there is no reason
you can't have different sizes for char*.

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Walter Bushell
2010-03-24 15:19:41 UTC
Permalink
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 01:53:56 -0700 (PDT)
Post by Nick Keighley
Post by glen herrmannsfeldt
(snip)
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a nice
example why, even now, Leenux weenies are not correct when they
insist that C has a flat memory model and all pointers are just
numbers.
Well, you could also read the C standard to learn that.
but if you say that you get accused of language lawyering.
"Since IBM stopped making 360s no C program ever needs to run on such
a platform"
Problem is that segmented memory model is much better when working
with 64 bit address space. Flat memory model wastes to much
RAM. It would be better for standard C and C++ to provide appropriate
pointer semantics in order to keep memory usage optimal.
What is use of 64 bit flat pointers when you can actually
just load segment base and work with offsets?
Actually compilers are forced to use maximum possible
size of pointer in order to cover all possible sizes,
because of memory model forced by C and C++.
This is not about segmented flat model.
It is about different addressing modes even in flat model.
It seems that besides flat memory model C and C++ assumes
always absolute addressing pointers.
Technically this limitation can be easily circumvented
if different sizes of pointers to same type are allowed.
Ok, void* should be maximum size, but there is no reason
you can't have different sizes for char*.
Greets!
But ram is *so* cheap these days. Can you think of a reason for a
million pointers at once? And that would be 0.008 gigabytes. Perhaps one
needs to be that conscious for embedded work, but then one is not
working with 64 bit addressing either.
--
A computer without Microsoft is like a chocolate cake without mustard.
Branimir Maksimovic
2010-03-24 15:26:37 UTC
Permalink
On Wed, 24 Mar 2010 11:19:41 -0400
Post by Walter Bushell
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 01:53:56 -0700 (PDT)
Post by Nick Keighley
Post by glen herrmannsfeldt
(snip)
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a
nice example why, even now, Leenux weenies are not correct
when they insist that C has a flat memory model and all
pointers are just numbers.
Well, you could also read the C standard to learn that.
but if you say that you get accused of language lawyering.
"Since IBM stopped making 360s no C program ever needs to run on
such a platform"
Problem is that segmented memory model is much better when working
with 64 bit address space. Flat memory model wastes to much
RAM. It would be better for standard C and C++ to provide...
But ram is *so* cheap these days. Can you think of a reason for a
million pointers at once? And that would be 0.008 gigabytes. Perhaps
one needs to be that conscious for embedded work, but then one is not
working with 64 bit addressing either.
Imagine double linked list.
You need two pointers. 16 bytes just for that instead of 8.
Take any data structure that has pointer in it.
You can easily consume more ram than available.
Say you waste 1gb of ram per process easily.
No matter how memory is cheap, if you don;t save
you will sooner or later hit the roof.
Why use 1gb of ram when 32 mb is enough?
Think about it. Problem is not in price of memory,
but nowadays memory is *wasted* so much .

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Walter Bushell
2010-03-24 16:16:41 UTC
Permalink
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 11:19:41 -0400
Post by Walter Bushell
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 01:53:56 -0700 (PDT)
Post by Nick Keighley
Post by glen herrmannsfeldt
(snip)
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a
nice example why, even now, Leenux weenies are not correct
when they insist that C has a flat memory model and all
pointers are just numbers.
Well, you could also read the C standard to learn that.
but if you say that you get accused of language lawyering.
"Since IBM stopped making 360s no C program ever needs to run on
such a platform"
Problem is that segmented memory model is much better when working
with 64 bit address space. Flat memory model wastes to much
RAM. It would be better for standard C and C++ to provide...
But ram is *so* cheap these days. Can you think of a reason for a
million pointers at once? And that would be 0.008 gigabytes. Perhaps
one needs to be that conscious for embedded work, but then one is not
working with 64 bit addressing either.
Imagine double linked list.
You need two pointers. 16 bytes just for that instead of 8.
Take any data structure that has pointer in it.
You can easily consume more ram than available.
Say you waste 1gb of ram per process easily.
No matter how memory is cheap, if you don;t save
you will sooner or later hit the roof.
Why use 1gb of ram when 32 mb is enough?
Think about it. Problem is not in price of memory,
but nowadays memory is *wasted* so much .
Greets!
Go virtual man. One does have to structure the data for the problem, but
if you are using that much space for pointers you are using more for the
data. Also you if 32 bits are enough you can pack two 32 bit addressen
in each 64 bit word and expand as necessary.

This from the top of my head. A little research could improve this
substantially I am quite sure.

A little more though, if the structure is of length N then we need only
store the base address and (relative pointer)/N which will be integer,
so we might be able to store data in the pointer word along with the two
pointers, or make create a balanced trinary or qunintary linked list or
even higher order.

Cheers.
--
A computer without Microsoft is like a chocolate cake without mustard.
Branimir Maksimovic
2010-03-24 16:33:54 UTC
Permalink
On Wed, 24 Mar 2010 12:16:41 -0400
Post by Walter Bushell
A little more though, if the structure is of length N then we need
only store the base address and (relative pointer)/N which will be
integer, so we might be able to store data in the pointer word along
with the two pointers, or make create a balanced trinary or qunintary
linked list or even higher order.
Cheers.
Voice of reason!

Cheers!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Joe Pfeiffer
2010-03-24 16:15:49 UTC
Permalink
Post by Walter Bushell
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 01:53:56 -0700 (PDT)
Post by Nick Keighley
Post by glen herrmannsfeldt
(snip)
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a nice
example why, even now, Leenux weenies are not correct when they
insist that C has a flat memory model and all pointers are just
numbers.
Well, you could also read the C standard to learn that.
but if you say that you get accused of language lawyering.
"Since IBM stopped making 360s no C program ever needs to run on such
a platform"
Problem is that segmented memory model is much better when working
with 64 bit address space. Flat memory model wastes to much
RAM. It would be better for standard C and C++ to provide appropriate
pointer semantics in order to keep memory usage optimal.
What is use of 64 bit flat pointers when you can actually
just load segment base and work with offsets?
Actually compilers are forced to use maximum possible
size of pointer in order to cover all possible sizes,
because of memory model forced by C and C++.
This is not about segmented flat model.
It is about different addressing modes even in flat model.
It seems that besides flat memory model C and C++ assumes
always absolute addressing pointers.
Technically this limitation can be easily circumvented
if different sizes of pointers to same type are allowed.
Ok, void* should be maximum size, but there is no reason
you can't have different sizes for char*.
Greets!
But ram is *so* cheap these days. Can you think of a reason for a
million pointers at once? And that would be 0.008 gigabytes. Perhaps one
needs to be that conscious for embedded work, but then one is not
working with 64 bit addressing either.
Besides, whatever relevance his arguments have, they apply to virtual
space, not physical RAM.
--
As we enjoy great advantages from the inventions of others, we should
be glad of an opportunity to serve others by any invention of ours;
and this we should do freely and generously. (Benjamin Franklin)
Branimir Maksimovic
2010-03-24 16:32:07 UTC
Permalink
On Wed, 24 Mar 2010 10:15:49 -0600
Post by Joe Pfeiffer
Post by Walter Bushell
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 01:53:56 -0700 (PDT)
Post by Nick Keighley
Post by glen herrmannsfeldt
(snip)
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a
nice example why, even now, Leenux weenies are not correct
when they insist that C has a flat memory model and all
pointers are just numbers.
Well, you could also read the C standard to learn that.
but if you say that you get accused of language lawyering.
"Since IBM stopped making 360s no C program ever needs to run on
such a platform"
Problem is that segmented memory model is much better when working
with 64 bit address space. Flat memory model wastes to much
RAM. It would be better for standard C and C++ to provide
appropriate pointer semantics in order to keep memory usage
optimal. What is use of 64 bit flat pointers when you can actually
just load segment base and work with offsets?
Actually compilers are forced to use maximum possible
size of pointer in order to cover all possible sizes,
because of memory model forced by C and C++.
This is not about segmented flat model.
It is about different addressing modes even in flat model.
It seems that besides flat memory model C and C++ assumes
always absolute addressing pointers.
Technically this limitation can be easily circumvented
if different sizes of pointers to same type are allowed.
Ok, void* should be maximum size, but there is no reason
you can't have different sizes for char*.
Greets!
But ram is *so* cheap these days. Can you think of a reason for a
million pointers at once? And that would be 0.008 gigabytes.
Perhaps one needs to be that conscious for embedded work, but then
one is not working with 64 bit addressing either.
Besides, whatever relevance his arguments have, they apply to virtual
space, not physical RAM.
Problem is that virtual address space is mapped to physical RAM.
You have to write OS in some language. Assembler?
I think that writing device drivers an Os is lot easier
in C than in Java. what do you think why?

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Joe Pfeiffer
2010-03-24 18:02:13 UTC
Permalink
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 10:15:49 -0600
Post by Joe Pfeiffer
Post by Walter Bushell
Post by Branimir Maksimovic
Problem is that segmented memory model is much better when working
with 64 bit address space. Flat memory model wastes to much
RAM. It would be better for standard C and C++ to provide
appropriate pointer semantics in order to keep memory usage
optimal. What is use of 64 bit flat pointers when you can actually
just load segment base and work with offsets?
Actually compilers are forced to use maximum possible
size of pointer in order to cover all possible sizes,
because of memory model forced by C and C++.
This is not about segmented flat model.
It is about different addressing modes even in flat model.
It seems that besides flat memory model C and C++ assumes
always absolute addressing pointers.
Technically this limitation can be easily circumvented
if different sizes of pointers to same type are allowed.
Ok, void* should be maximum size, but there is no reason
you can't have different sizes for char*.
Greets!
But ram is *so* cheap these days. Can you think of a reason for a
million pointers at once? And that would be 0.008 gigabytes.
Perhaps one needs to be that conscious for embedded work, but then
one is not working with 64 bit addressing either.
Besides, whatever relevance his arguments have, they apply to virtual
space, not physical RAM.
Problem is that virtual address space is mapped to physical RAM.
You have to write OS in some language. Assembler?
I think that writing device drivers an Os is lot easier
in C than in Java. what do you think why?
No, a very small fraction of the virtual address space is mapped to
physical RAM.
--
As we enjoy great advantages from the inventions of others, we should
be glad of an opportunity to serve others by any invention of ours;
and this we should do freely and generously. (Benjamin Franklin)
Branimir Maksimovic
2010-03-24 19:24:09 UTC
Permalink
On Wed, 24 Mar 2010 12:02:13 -0600
Post by Joe Pfeiffer
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 10:15:49 -0600
Post by Joe Pfeiffer
Post by Walter Bushell
Post by Branimir Maksimovic
Problem is that segmented memory model is much better when
working with 64 bit address space. Flat memory model wastes to
much RAM. It would be better for standard C and C++ to provide
appropriate pointer semantics in order to keep memory usage
optimal. What is use of 64 bit flat pointers when you can
actually just load segment base and work with offsets?
Actually compilers are forced to use maximum possible
size of pointer in order to cover all possible sizes,
because of memory model forced by C and C++.
This is not about segmented flat model.
It is about different addressing modes even in flat model.
It seems that besides flat memory model C and C++ assumes
always absolute addressing pointers.
Technically this limitation can be easily circumvented
if different sizes of pointers to same type are allowed.
Ok, void* should be maximum size, but there is no reason
you can't have different sizes for char*.
Greets!
But ram is *so* cheap these days. Can you think of a reason for
a million pointers at once? And that would be 0.008 gigabytes.
Perhaps one needs to be that conscious for embedded work, but
then one is not working with 64 bit addressing either.
Besides, whatever relevance his arguments have, they apply to
virtual space, not physical RAM.
Problem is that virtual address space is mapped to physical RAM.
You have to write OS in some language. Assembler?
I think that writing device drivers an Os is lot easier
in C than in Java. what do you think why?
No, a very small fraction of the virtual address space is mapped to
physical RAM.
Hm , why then people have problem with Linux OOM killer, especially
regarding Java GC. It has to pick targets more nicely not
in random manner;) (and those machines have 4gb of ram)
Problem is that I cn see no improvement over older hardware...
and much less RAM...

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Joe Pfeiffer
2010-03-24 20:34:35 UTC
Permalink
Post by Branimir Maksimovic
On Wed, 24 Mar 2010 12:02:13 -0600
Post by Joe Pfeiffer
No, a very small fraction of the virtual address space is mapped to
physical RAM.
Hm , why then people have problem with Linux OOM killer, especially
regarding Java GC. It has to pick targets more nicely not
in random manner;) (and those machines have 4gb of ram)
Problem is that I cn see no improvement over older hardware...
and much less RAM...
I haven't had any problem with the OOM killer since the last time a
sysadmin forgot to turn swap on.
--
As we enjoy great advantages from the inventions of others, we should
be glad of an opportunity to serve others by any invention of ours;
and this we should do freely and generously. (Benjamin Franklin)
Phil Carmody
2010-03-24 23:47:34 UTC
Permalink
Post by Branimir Maksimovic
Post by Joe Pfeiffer
No, a very small fraction of the virtual address space is mapped to
physical RAM.
Hm , why then people have problem with Linux OOM killer,
Because they are using vastly more virtual address space
than there is physical RAM. Which kinda follows from what
Joe already said.

Phil
--
I find the easiest thing to do is to k/f myself and just troll away
-- David Melville on r.a.s.f1
Branimir Maksimovic
2010-03-25 09:18:01 UTC
Permalink
On Thu, 25 Mar 2010 01:47:34 +0200
Post by Phil Carmody
Post by Branimir Maksimovic
Post by Joe Pfeiffer
No, a very small fraction of the virtual address space is mapped to
physical RAM.
Hm , why then people have problem with Linux OOM killer,
Because they are using vastly more virtual address space
than there is physical RAM.
Which kinda follows from what
Joe already said.
Yes, but you have to know how much GB of swap to enable.
Besides that then everything runs sluggish.

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
jmfbahciv
2010-03-25 13:32:52 UTC
Permalink
Post by Branimir Maksimovic
On Thu, 25 Mar 2010 01:47:34 +0200
Post by Phil Carmody
Post by Branimir Maksimovic
Post by Joe Pfeiffer
No, a very small fraction of the virtual address space is mapped to
physical RAM.
Hm , why then people have problem with Linux OOM killer,
Because they are using vastly more virtual address space
than there is physical RAM.
Which kinda follows from what
Joe already said.
Yes, but you have to know how much GB of swap to enable.
Besides that then everything runs sluggish.
Huh? Are you stating that the system goes sluggish when
you turn swapping on?

/BAH
Branimir Maksimovic
2010-03-25 13:20:56 UTC
Permalink
On Thu, 25 Mar 2010 08:32:52 -0500
Post by jmfbahciv
Post by Branimir Maksimovic
On Thu, 25 Mar 2010 01:47:34 +0200
Post by Phil Carmody
Post by Branimir Maksimovic
Post by Joe Pfeiffer
No, a very small fraction of the virtual address space is mapped
to physical RAM.
Hm , why then people have problem with Linux OOM killer,
Because they are using vastly more virtual address space
than there is physical RAM.
Which kinda follows from what
Joe already said.
Yes, but you have to know how much GB of swap to enable.
Besides that then everything runs sluggish.
Huh? Are you stating that the system goes sluggish when
you turn swapping on?
Obviously not. I claim that everything runs sluggish when
OS have to employ swapping. In this case problem is
GC as it scans (*all memory for references*)
thus forcing heavy swaping. You don;t have such
problems with malloc/free.

Greets
--
http://maxa.homedns.org/

Sometimes online sometimes not
jmfbahciv
2010-03-25 14:18:42 UTC
Permalink
Post by Branimir Maksimovic
On Thu, 25 Mar 2010 08:32:52 -0500
Post by jmfbahciv
Post by Branimir Maksimovic
On Thu, 25 Mar 2010 01:47:34 +0200
Post by Phil Carmody
Post by Branimir Maksimovic
Post by Joe Pfeiffer
No, a very small fraction of the virtual address space is mapped
to physical RAM.
Hm , why then people have problem with Linux OOM killer,
Because they are using vastly more virtual address space
than there is physical RAM.
Which kinda follows from what
Joe already said.
Yes, but you have to know how much GB of swap to enable.
Besides that then everything runs sluggish.
Huh? Are you stating that the system goes sluggish when
you turn swapping on?
Obviously not. I claim that everything runs sluggish when
OS have to employ swapping.
You are wrong.
Post by Branimir Maksimovic
In this case problem is
GC as it scans (*all memory for references*)
thus forcing heavy swaping. You don;t have such
problems with malloc/free.
It sounds like you have a lot more to learn about how
code works and doesn't work.

/BAH
Jonathan de Boyne Pollard
2010-03-24 18:12:15 UTC
Permalink
But [virtual address space] is *so* cheap these days. Can you think of
a reason for a million pointers at once? And that would be 0.008
gigabytes.
One third of a million items in a non-intrusive doubly-linked list? (-:

Before the "But, but, but! A program would never want them all at once!"
sputtering comes along from anyone, I point out that this happens
regularly, even for people without Big Problems To Solve. For example:
One of the newsgroups for this very post is alt.folklore.computers. My
Usenet node carries all of the (correctly formatted) messages in that
newsgroup (that I've been able to find) for the past half decade.
That's currently a little over 127,500 messages. My NUA's thread-view
pane of course needs to be capable of displaying the NOV data for all of
those messages, sorted into the viewing order that I have selected. So
it has at least that many objects in memory in some form of data
structure when it is presenting that newsgroup.
bbreynolds
2010-03-25 02:50:48 UTC
Permalink
On Mar 24, 2:12�pm, Jonathan de Boyne Pollard <J.deBoynePollard-
Post by Jonathan de Boyne Pollard
But [virtual address space] is *so* cheap these days. Can you think of
a reason for a million pointers at once? And that would be 0.008
gigabytes.
Before the "But, but, but! A program would never want them all at once!"
sputtering comes along from anyone, I point out that this happens
One of the newsgroups for this very post is alt.folklore.computers. �My
Usenet node carries all of the (correctly formatted) messages in that
newsgroup (that I've been able to find) for the past half decade. �
That's currently a little over 127,500 messages. My NUA's thread-view
pane of course needs to be capable of displaying the NOV data for all of
those messages, sorted into the viewing order that I have selected. �So
it has at least that many objects in memory in some form of data
structure when it is presenting that newsgroup.
And the purpose of such a capability? Why, of course---to be
able to determine how many of /BAH's postings to a.f.c. begin
with the exclamation "Sigh!".

Bruce B. Reynolds, Trailing Edge Technologies, Warminster PA
jmfbahciv
2010-03-25 13:27:48 UTC
Permalink
Post by bbreynolds
On Mar 24, 2:12�pm, Jonathan de Boyne Pollard <J.deBoynePollard-
Post by Jonathan de Boyne Pollard
But [virtual address space] is *so* cheap these days. Can you think of
a reason for a million pointers at once? And that would be 0.008
gigabytes.
Before the "But, but, but! A program would never want them all at once!"
sputtering comes along from anyone, I point out that this happens
One of the newsgroups for this very post is alt.folklore.computers. �My
Usenet node carries all of the (correctly formatted) messages in that
newsgroup (that I've been able to find) for the past half decade. �
That's currently a little over 127,500 messages. My NUA's thread-view
pane of course needs to be capable of displaying the NOV data for all of
those messages, sorted into the viewing order that I have selected. �So
it has at least that many objects in memory in some form of data
structure when it is presenting that newsgroup.
And the purpose of such a capability? Why, of course---to be
able to determine how many of /BAH's postings to a.f.c. begin
with the exclamation "Sigh!".
ROTFLMAO. It's beginning to sound as if the poster cannot
"lose control" by having stuff stored on disk, swapped nor
off-line. Another control freak.


/BAH
glen herrmannsfeldt
2010-03-24 21:19:42 UTC
Permalink
In alt.sys.pdp10 Walter Bushell <***@panix.com> wrote:
(snip)
Post by Walter Bushell
But ram is *so* cheap these days. Can you think of a reason for a
million pointers at once? And that would be 0.008 gigabytes. Perhaps one
needs to be that conscious for embedded work, but then one is not
working with 64 bit addressing either.
RAM is cheap, but bandwidth isn't. Bigger pointers means more
data transfer to/from memory and slower running programs.

-- glen
Branimir Maksimovic
2010-03-24 21:31:26 UTC
Permalink
On Wed, 24 Mar 2010 21:19:42 +0000 (UTC)
Post by glen herrmannsfeldt
(snip)
Post by Walter Bushell
But ram is *so* cheap these days. Can you think of a reason for a
million pointers at once? And that would be 0.008 gigabytes.
Perhaps one needs to be that conscious for embedded work, but then
one is not working with 64 bit addressing either.
RAM is cheap, but bandwidth isn't. Bigger pointers means more
data transfer to/from memory and slower running programs.
-- glen
Speaking to that I found that traversing linked list where
nodes are sorted by address is twice as fast than where
nodes are randomly sorted. Also found that quicksort that
is based on sequential memory access is much faster
than any sort based on random access. Same sort is
about 7 times faster when nodes are allocated behind
one another sorted by address and about 3-4 times
faster when there is larger gap between nodes.
That's why linked list sorts that change access order
are really bad thing, since after them traversing said list
is at least twice slower.
Eg random access radix sort of 5million nodes (512kb L@ cache dual
xeon ) is slower than first quick sort list by address, then
quick sort list by value by *sequential* access.
Of course that is if nodes are smaller ;)
That is for intel. Didn;t try amd.
Also tested initialization of 256 meg of ram
on modern quad xeon (external memory controller),and
home model dual athlon , same speed can you beleive?!
4 threads xeon , two threads athlon.
All in all nowadays it is more important to
pay attention on memory access patterns than anything else.

Greets
--
http://maxa.homedns.org/

Sometimes online sometimes not
Phil Carmody
2010-03-24 23:44:39 UTC
Permalink
Post by Walter Bushell
Post by Branimir Maksimovic
Problem is that segmented memory model is much better when working
with 64 bit address space. Flat memory model wastes to much
RAM. It would be better for standard C and C++ to provide appropriate
pointer semantics in order to keep memory usage optimal.
What is use of 64 bit flat pointers when you can actually
just load segment base and work with offsets?
...
Post by Walter Bushell
But ram is *so* cheap these days. Can you think of a reason for a
million pointers at once? And that would be 0.008 gigabytes. Perhaps one
needs to be that conscious for embedded work, but then one is not
working with 64 bit addressing either.
64-bit Alpha, POWER, and MIPS architectures have been used in
embedded applications, complete with their native 64-bit
addressing.

Phil
--
I find the easiest thing to do is to k/f myself and just troll away
-- David Melville on r.a.s.f1
Branimir Maksimovic
2010-03-25 09:16:28 UTC
Permalink
On Thu, 25 Mar 2010 01:44:39 +0200
Post by Phil Carmody
Post by Walter Bushell
Post by Branimir Maksimovic
Problem is that segmented memory model is much better when working
with 64 bit address space. Flat memory model wastes to much
RAM. It would be better for standard C and C++ to provide
appropriate pointer semantics in order to keep memory usage
optimal. What is use of 64 bit flat pointers when you can actually
just load segment base and work with offsets?
...
Post by Walter Bushell
But ram is *so* cheap these days. Can you think of a reason for a
million pointers at once? And that would be 0.008 gigabytes.
Perhaps one needs to be that conscious for embedded work, but then
one is not working with 64 bit addressing either.
64-bit Alpha, POWER, and MIPS architectures have been used in
embedded applications, complete with their native 64-bit
addressing.
I guess they are more powerful than mainframes used in 70's and 80's ;)
In my router there is MIPS with *16mb* of RAM.
Unisis A mainframe had 4mb of RAM ;) (one that I worked on)

Greets!
--
http://maxa.homedns.org/

Sometimes online sometimes not
Mark Crispin
2010-03-24 16:13:49 UTC
Permalink
Post by Nick Keighley
Post by glen herrmannsfeldt
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a nice
example why, even now, Leenux weenies are not correct when they insist
that C has a flat memory model and all pointers are just numbers.
Well, you could also read the C standard to learn that.
but if you say that you get accused of language lawyering.
"Since IBM stopped making 360s no C program ever needs to run on such
a platform"
And, as you probably know, people who say such things are mindless
cretins who, "in a civilized society, would be sent to a state laboratory
for experimental purposes." Such people are boxing themselves into a
corner; they just don't realize it yet.

I will laugh myself silly when the latest & greatest CPU uses something
other than numbers for pointers, and we can see a reprise of "all the
world is not VAX."

-- Mark --

http://panda.com/mrc
Democracy is two wolves and a sheep deciding what to eat for lunch.
Liberty is a well-armed sheep contesting the vote.
Peter Flass
2010-03-24 21:29:45 UTC
Permalink
Post by Mark Crispin
Post by Nick Keighley
Post by glen herrmannsfeldt
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a nice
example why, even now, Leenux weenies are not correct when they insist
that C has a flat memory model and all pointers are just numbers.
Well, you could also read the C standard to learn that.
but if you say that you get accused of language lawyering.
"Since IBM stopped making 360s no C program ever needs to run on such
a platform"
And, as you probably know, people who say such things are mindless
cretins who, "in a civilized society, would be sent to a state
laboratory for experimental purposes." Such people are boxing
themselves into a corner; they just don't realize it yet.
I will laugh myself silly when the latest & greatest CPU uses something
other than numbers for pointers, and we can see a reprise of "all the
world is not VAX."
I suppose you could have associative pointers.
Jonathan de Boyne Pollard
2010-03-25 02:07:12 UTC
Permalink
Post by Mark Crispin
I will laugh myself silly when the latest & greatest CPU uses
something other than numbers for pointers, and we can see a reprise of
"all the world is not VAX" .
Heh! I had to look that one up. (It's Commandment #10 in Henry
Spencer's Ten Commandments for C Programmers, for the benefits of the
lurkers.)

The thing is, you can laugh yourself silly now. Henry Spencer gave "All
the world's a 386." as a heresy equivalent to "All the world's a VAX.".
The people who argue that the whole planet is flat, because their
platform of choice gives them a tiny/flat memory model, are forgetting
that the very processor architecture that they are using is one of the
reasons that the C and C++ languages are careful not to provide such
sweeping conversion (and other) semantics for pointers in the first place.

They forget the many cries of the programmers using the very same
processor architecture that they are now using to argue the flatness of
the globe. "My code is far but my data are near and I cannot therefore
cast from pointer to function to pointer to data without loss of
information!" "DS isn't equal to CS and I cannot therefore cast from
near pointer to function to near pointer to data and have the pointers
point to the same thing!" "16-bit OS/2/Windows has loaded my constants
into a read-only segment and so my program will crash if I attempt to
write to a string constant!" "My array of data has been allocated a
single segment of its own by the heap manager, so running off the end of
the array will immediately exceed the segment limit and crash the
program!" "My program is huge model, therefore size_t is wider than
unsigned int!" "16-bit OS/2/Windows invalidates freed LDT selectors, so
even if I don't dereference it, merely just using the value of a pointer
to deallocated memory in an expression, which will often attempt to load
a now invalid LDT selector into a processor segment register, will cause
my program to crash!"
glen herrmannsfeldt
2010-03-25 03:46:18 UTC
Permalink
Post by Jonathan de Boyne Pollard
The thing is, you can laugh yourself silly now. Henry Spencer gave "All
the world's a 386." as a heresy equivalent to "All the world's a VAX.".
The people who argue that the whole planet is flat, because their
platform of choice gives them a tiny/flat memory model, are forgetting
that the very processor architecture that they are using is one of the
reasons that the C and C++ languages are careful not to provide such
sweeping conversion (and other) semantics for pointers in the first place.
Maybe one of the reasons, but machines like the PDP-10 are another.

There is consideration for C pointers being different for
different types, especially on word addressed machines.

Consider a PDP-10 C system with 9 bit char, four per word.
Now, cast between (int*) and (char*) and see what happens?

I presume an (int*) is the PDP-10 address of the word, but
what is in a (char*)?

Also possible is an 18 bit (char) using H instructions.

-- glen
Richard Bos
2010-03-24 09:48:13 UTC
Permalink
Post by glen herrmannsfeldt
Post by Richard Bos
That crossposting was, for once, not asinine. It served as a nice
example why, even now, Leenux weenies are not correct when they insist
that C has a flat memory model and all pointers are just numbers.
Well, you could also read the C standard to learn that.
Yes, but Leenux weenies who post to comp.lang.c are frequently found to
be remarkably unable either to do that, or to believe that what they
read there applies to what it pleases them to call "the real world"
(i.e., Leenux-weenieworld).

Richard
Continue reading on narkive:
Loading...