Re: Proposal for limited pointers
- From: Michal Nazarewicz <mina86@xxxxxxx>
- Date: Fri, 11 Jun 2010 12:26:08 +0200
"Kenneth 'Bessarion' Boyd" <zaimoni@xxxxxxxxxxx> writes:
On Jun 10, 12:06 pm, Michal Nazarewicz <min...@xxxxxxx> wrote:
"Kenneth 'Bessarion' Boyd" <zaim...@xxxxxxxxxxx> writes:
On Jun 9, 1:25 pm, Per <per.mathi...@xxxxxxxxx> wrote:
This is a proposal to compiler writers and the C standards committee
to add a new type of pointers to the language that I have chosen to
call "limited pointers". It is a pointer that always knows the size of
what it points to.
Ahem...let's simplify this: all that is really necessary for 99% of
the important cases is that the current requested size of a dynamic
memory block allocated by malloc/calloc/realloc be immediately
available at all times.
Not at all. Size of allocated memory is not enough. In no matter.
Please, name a use case. Recall that given the size of allocated
memory in bytes, it's a rote conversion for a given type T to scale to
complete objects in the array (just divide by sizeof(T))
This was already pointed, I have also pointed it in another reply, I'll
point it one again:
struct foo {
char foo[4];
} *foos = mlloc(100);
Size/length of foos->foo is 4 not 100.
Converting *all* dynamically allocated pointers to be "limited" as you
propose was trivial; it's a freebie of being able to verify at run-
time both whether a dynamically allocated array access is in bounds,
and whether a free/realloc call is valid. So the only extension
needed is the _Lengthof/lengthof/... functionality; the type system
extension is completely unnecessary.
See above example where your approach fails plus this works only for
dynamic memory. Static and automatic cannot be verified in that way.
Even for dynamic allocation checking size may be troublesome
(ie. require considerable time and/or memory for control structures), as
in: foos[50].foo if we take my above example.
--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86-tlen.pl>--<jid:mina86-jabber.org>--ooO--(_)--Ooo--
.
- Follow-Ups:
- Re: Proposal for limited pointers
- From: Kenneth 'Bessarion' Boyd
- Re: Proposal for limited pointers
- References:
- Proposal for limited pointers
- From: Per
- Re: Proposal for limited pointers
- From: Kenneth 'Bessarion' Boyd
- Re: Proposal for limited pointers
- From: Michal Nazarewicz
- Re: Proposal for limited pointers
- From: Kenneth 'Bessarion' Boyd
- Proposal for limited pointers
- Prev by Date: Re: Proposal for limited pointers
- Next by Date: Re: Proposal for limited pointers
- Previous by thread: Re: Proposal for limited pointers
- Next by thread: Re: Proposal for limited pointers
- Index(es):
Relevant Pages
|