Operating System - HP-UX
1753899 Members
7694 Online
108809 Solutions
New Discussion юеВ

Re: malloc problem in porting HPUX 10.20 code on HPUX 11.11

 
SOLVED
Go to solution
Suhas_3
Advisor

malloc problem in porting HPUX 10.20 code on HPUX 11.11

Hi all,

I have a problem in porting my HPUX 10.20 application (c code) to HPUX
11.11. Whenever there is calloc or realloc function, the application
coredumps and aborts.
I have to compile the programs using +DD64 option, as the application
uses informix objects which come pre-compiled using +DD64 option. I have
simulated the condition in one small program given below, which works on
10.20 and works on 11.11 if compiled without +DD64 option. But does not
work if compiled on 11.11 with +DD64 option.

Thanks for the help,
Suhas

cc -Aa +DD64

#define ALLOC(PTR) PTR=(struct ob *) calloc(2,sizeof(struct ob));

struct ob{
int nitin;
char kicha;
};
#include
main(){
int * ptr;
int a[16]={1,2,3,4,5,6,7,8,9,0,1,2,3,4};
struct ob *ob1;
ALLOC(ob1)
ptr=a;
ob1->nitin=10;
ob1->kicha='c';
printf("%d,%c",ob1->nitin,ob1->kicha);
}
3 REPLIES 3
harry d brown jr
Honored Contributor

Re: malloc problem in porting HPUX 10.20 code on HPUX 11.11


You need to ADD

#include

live free or die
harry
Live Free or Die
David Johns
Advisor
Solution

Re: malloc problem in porting HPUX 10.20 code on HPUX 11.11

Hi Suhas:

If you #include above the macro the program runs fine. I think the calloc function needs a prototype, or the compiler assumes it returns a 4 byte integer instead of an 8 byte pointer to void. The address after the cast to (struct ob *) is not in the process space and gives a memory access fault.

Cheers,
Dave
A. Clay Stephenson
Acclaimed Contributor

Re: malloc problem in porting HPUX 10.20 code on HPUX 11.11

The answer to this is that your code (even on 10.20) was working by accident. If you had added stdlib.h to your #includes, all would have been well.

As has already been indicated, the fundamental problem is that without a prototype, functions are assumed to be int. In the 32-bit world or the +DA32 model int and *ptr are the same size but in the +DD64 model int is 4 bytes and *ptr is 8 bytes.



If it ain't broke, I can fix that.