Another reason to always check is so that you have Safe
Programming Practices that are platform independent.  If you
always check the return, you will always be correct.  And as Phil
says below, it is very possible to exceed 16meg in allocations.

Another one I've had discussions over is signed vs unsigned
char's and binary data.  In the Intel world, a data type of char
is actually unsigned char.  But on the /400, it is signed char.
So when you put binary data into that in the Intel world, it
works.  But on the /400, you can get "undesired" results.  So
rather than try to remember which is which, I always use BYTE
(typedef'd to unsigned char) for binary data.  This way I don't
have to remember and I'm explicitly stating that the data is
binary.

Also, I might have it reversed...Intel might default to signed
and the /400 be unsigned.  But it doesn't matter to me as I use
BYTE!

Safe programming is always important.  But in C/C++, it is even
more important than with RPG. 

JMHO,
Bob Crothers

> -----Original Message-----
> From: c400-l-bounces@xxxxxxxxxxxx 
> [mailto:c400-l-bounces@xxxxxxxxxxxx] On Behalf Of Hall, Philip
> Sent: Friday, August 29, 2003 8:38 AM
> To: C programming iSeries / AS400
> Subject: RE: [C400-L] Testing malloc results for null on the 
> 400(was:HTTPAuthentication / base64 encoder?)
> 
> 
> 
> > But what I'd really like to know - is there any reason for 
> > OS/400 to return NULL after calling for example 
> >  r = (char *) malloc(1000000) ;
> > 
> > I cannot see any reason, why malloc would return NULL, other 
> > than expiring address space, which is 2**64 - and I even 
> > cannot imagine, how many times I'd have to call 
> > abovementioned malloc, before I'll get NULL...
> 
> A simple reason is that the [c][m][re]alloc() functions do 
> have limits on the iSeries, it's ~ 16MB for all allocations. 
> So, of course, if your program tries to allocate more than 
> that over the it's life-cycle, you will get NULL returned. 
> Don't be confused by the iSeries' single level storage, it 
> doesn't 'appear' as such to ILE/C.  To counter this, you can 
> of course use the Terabyte storage compiler option to allow 
> larger than 16MB allocations.
> 
> Also, realloc() can fail if the pointer to be realloc'ed to 
> points somewhere it shouldn't.
> 
> --phil



This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact [javascript protected email address].