comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve" <nospam_steved94@comcast.net>
Subject: Re: memory management
Date: Thu, 2 Jun 2005 18:41:07 -0700
Date: 2005-06-02T18:41:07-07:00	[thread overview]
Message-ID: <M-GdnSTkAoGSKALfRVn-vQ@comcast.com> (raw)
In-Reply-To: wccoeav8tin.fsf@shell01.TheWorld.com

"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message 
news:wccoeav8tin.fsf@shell01.TheWorld.com...
[snip]
> When I say "pointer", I don't mean it has to be implemented as a single
> machine address.  It could be an offset from some known base address, an
> index into an array, or (as you say) a fat pointer -- among other
> things.
>
> The same is true of pointers in C and C++ -- an implementation is free
> to implement pointers as something other than a machine address.  In
> fact, if a C compiler wishes to check array bounds, it pretty much *has*
> to use fat pointers.  I know of one C compiler that did just that.  My
> point is that "pointer" is not synonymous with "single machine address",
> even in C.

While some C/C++ compilers may have checked array bounds, I'm not so sure it 
complies with a standard.  I don't have a copy of the standard available to 
check.

I do know that it is a common C idiom to describe a structure something 
like:

struct Data_Container
{
    int nbValues;
    int data[1];
}

...
numElements = 100;
struct Data_Container* dc = malloc( sizeof(Data_Container) + sizeof(int) 
*( numElements - 1));

dc->nbValues = numElements;
for( i = 0 ; i < dc->nbValues ; i++ )
{
    dc->data[ i ] = 0;
}

Which would not work if array bounds were checked.

I have heard of tools that will do array bounds checking with C, that give 
some way of describing the above example, but I don't think it is really 
part of the C/C++ standard.

I'm suprised the compiler that did check array bounds was validated... oh 
wait a minute ;-)

Steve
(The Duck)





  parent reply	other threads:[~2005-06-03  1:41 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-26  0:57 memory management alex goldman
2005-05-26  2:14 ` David C. Hoos, Sr.
2005-05-26 13:21   ` Steve
2005-05-26 18:40     ` alex goldman
2005-05-28  2:13       ` Steve
2005-05-28  5:19         ` Jeffrey Carter
2005-05-28 14:48           ` Steve
2005-05-26 18:47     ` Pascal Obry
2005-05-27 14:33   ` Martin Krischik
2005-05-26 12:10 ` Robert A Duff
2005-05-27 14:31   ` Martin Krischik
2005-05-28 11:44     ` Robert A Duff
2005-05-28 13:03       ` Simon Wright
2005-05-31 12:04         ` Robert A Duff
2005-06-02 15:42       ` Thomas Maier-Komor
2005-06-02 17:05         ` Robert A Duff
2005-06-03  1:41       ` Steve [this message]
2005-06-03 10:12         ` alex goldman
2005-06-13  4:01         ` Dave Thompson
  -- strict thread matches above, loose matches on Subject: below --
2005-04-19 20:30 Memory_Management Anh Vo
2005-04-19  1:39 Memory_Management Bini
2005-04-19  9:18 ` Memory_Management Duncan Sands
2005-04-20  1:06   ` Memory_Management Bini
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox