Re: (MS-)DOS PC on a microcontroller??
- From: Jack Klein <jackklein@xxxxxxxxxxx>
- Date: Tue, 23 Oct 2007 21:38:59 -0500
On Tue, 23 Oct 2007 17:30:28 -0400, CBFalconer <cbfalconer@xxxxxxxxx>
wrote in comp.arch.embedded:
larwe wrote:
Vladimir Vassilevsky <antispam_bo...@xxxxxxxxxxx> wrote:
For example: in the MS DOS, it is perfectly valid to allocate a
memory block of zero bytes. In PTS-DOS and some others it results
in an error. It appears that surprisingly many programs are
actually making the requests of zero bytes, so here is a
compatibility problem.
Let me guess... the 0 byte malloc code is in the runtime libraries
for Microsoft C, so that no kosher program will run properly on
non-kosher DOS clones.
See the following from the C standard. Note the provision for a
size request of zero. This is easily missed, because it applies to
all of malloc, realloc, and calloc and thus is isolated in the
standard.
7.20.3 Memory management functions
[#1] The order and contiguity of storage allocated by
successive calls to the calloc, malloc, and realloc
functions is unspecified. The pointer returned if the
allocation succeeds is suitably aligned so that it may be
assigned to a pointer to any type of object and then used to
access such an object or an array of such objects in the
space allocated (until the space is explicitly freed or
reallocated). Each such allocation shall yield a pointer to
an object disjoint from any other object. The pointer
returned points to the start (lowest byte address) of the
allocated space. If the space cannot be allocated, a null
pointer is returned. If the size of the space requested is |
zero, the behavior is implementation-defined: either a null |
pointer is returned, or the behavior is as if the size were |
some nonzero value, except that the returned pointer shall |
not be used to access an object. The value of a pointer |
that refers to freed space is indeterminate. |
|
This is the critical provision ----------------------'
Chuck, I think you're missing the point here. There is not
necessarily a relationship between the C library being required to
support malloc/calloc requests for 0 bytes and whether or not the
operating system chokes on zero bytes.
Given any real world implementation of malloc etc., a C library will
do one of the following:
-- return a NULL pointer without even calling the OS allocation
routine.
-- call the OS allocation routine for a block of (requested size +
internal header size) bytes. On real mode MS-DOS and clones running
in 16-bit real mode on x86, the internal header is almost certainly 16
bytes (one "paragraph"). Even if the requested value is left at 0 and
not rounded up to one "paragraph" of 16 bytes, if the library calls
the OS at all, it will almost certainly be for 16 bytes.
The differences in the responses of different DOS clones to a call to
allocate 0 paragraphs would never be seen by any DOS C library I have
ever used.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
.
- Follow-Ups:
- Re: (MS-)DOS PC on a microcontroller??
- From: CBFalconer
- Re: (MS-)DOS PC on a microcontroller??
- References:
- (MS-)DOS PC on a microcontroller??
- From: Paul Rosen
- Re: (MS-)DOS PC on a microcontroller??
- From: karthikbalaguru
- Re: (MS-)DOS PC on a microcontroller??
- From: Vladimir Vassilevsky
- Re: (MS-)DOS PC on a microcontroller??
- From: larwe
- Re: (MS-)DOS PC on a microcontroller??
- From: CBFalconer
- (MS-)DOS PC on a microcontroller??
- Prev by Date: Re: elimination of intercharacter gap in RS232 stream?
- Next by Date: Re: elimination of intercharacter gap in RS232 stream?
- Previous by thread: Re: (MS-)DOS PC on a microcontroller??
- Next by thread: Re: (MS-)DOS PC on a microcontroller??
- Index(es):
Relevant Pages
|
|