× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Mihael:

It is not simply just a matter of replacing every occurance of alloca() with malloc() ... you must also insert the corresponding free() calls at the appropriate place -- at the "end of scope" for the function (just before the function returns) ... but you must also consider other ways that the function could implicitly exit this scope, such as a longjump ... or due to exception handling.

I suggest you create your own include file, called e.g. "alloca.h" that looks something like this (for OS/400):

#ifndef _alloca_
#define _alloca_
#include <mih/modasa.h>
#define alloca(s1) (modasa(s1))
#endif

This will automatically include the MIH/MODASA header file, and define a macro named "alloca" that changes any occurance of alloca in your source code to a direct call to modasa. Then, you only need to include this near the beginning of any source that uses alloca, e.g.:

#include "alloca.h"

All the best,

Mark

On 12/6/2010 1:30 AM, Schmidt, Mihael wrote:
Thanx. I'll probably go that route.

Mihael

-----Original Message-----
From:c400-l-bounces+mihael.schmidt=rossmann.de@xxxxxxxxxxxx [mailto:c400-l-bounces+mihael.schmidt=rossmann.de@xxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Sunday, December 05, 2010 7:45 PM
To: C programming iSeries / AS400
Subject: Re: [C400-L] no alloca() available - alternative?

I'd change the ported code to use malloc(), and add code to clean up the
allocations (as appropriate)

That way, your code would be portable, run anywhere, etc.

If you use a MI call, such as _modasa, that code will only run on IBM
i... if you try to port to another system that doesn't have alloca(),
you'll need a separate workaround for that system, and you end up with
20+ sections of #define macros for compatibility.

Better to use malloc/free and write it in a portable fashion in the
first place. (I'd only write my own alloca() if changing to malloc()
would be too time-consuming.)


On 12/3/2010 1:46 PM, Schmidt, Mihael wrote:
Hi,

the ported software uses alloca() at some locations. Obviously alloca() is not support on IBM i. What is the alternative? malloc? What do I have to take into account when changing this to malloc? (besides freeing the memory afterwards)

Thanx in advance

Mihael Schmidt
Anwendungsentwicklung

Dirk Rossmann GmbH
Iserhägener Str.16
30938 Burgwedel
* +49 (05139) 898 - 4353

Handelsregister-Nr. HRB 120546, Amtsgericht Hannover
Ust-Id-Nr. DE 115055186
St.-Nr. 16 / 205 / 65401
Geschäftsführer: Dirk Roßmann, Alice Schardt-Roßmann, Roland Frobel, Klaus Praus



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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

This mailing list archive is Copyright 1997-2024 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 on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.