L
leptone
Dear all,
I am programming a PLC with an 80188 processor, hence I am using an
old version of Borland C++ (3.10). While doing the job, I've
encountered strange behaviours and I've isolated the problem that
seems to be related to a malloc function. I wrote a little piece of
code to reproduce the situation:
#include <stdlib.h>
#include <stdio.h>
typedef struct {
int a;
int b;
} BEAM_PROFILE;
int main(void){
BEAM_PROFILE * bpp;
int i;
bpp=(BEAM_PROFILE *)malloc(sizeof(BEAM_PROFILE));
printf("Memory was allocated at address %.8X\n", bpp);
bpp=(BEAM_PROFILE *)malloc(sizeof(BEAM_PROFILE));
printf("Memory was allocated at address %.8X\n", bpp);
}
When I use the small memory model, everything runs smoothly. The
problem is when I use the Large memory model. In this case the program
output is the following:
C:\BCTEST>tstmall
Memory was allocated at address 00000004
Memory was allocated at address 00000004
Every call to malloc returns exactly the same address (not null). I've
verified that the sizeof(BEAM_PROFILE * ) is 4 bytes with the large
memory model and 2 bytes with the small memory model, so I really
cannot figure out where the problem is...
Hope you have some clue about it...
Regards
Nicola
I am programming a PLC with an 80188 processor, hence I am using an
old version of Borland C++ (3.10). While doing the job, I've
encountered strange behaviours and I've isolated the problem that
seems to be related to a malloc function. I wrote a little piece of
code to reproduce the situation:
#include <stdlib.h>
#include <stdio.h>
typedef struct {
int a;
int b;
} BEAM_PROFILE;
int main(void){
BEAM_PROFILE * bpp;
int i;
bpp=(BEAM_PROFILE *)malloc(sizeof(BEAM_PROFILE));
printf("Memory was allocated at address %.8X\n", bpp);
bpp=(BEAM_PROFILE *)malloc(sizeof(BEAM_PROFILE));
printf("Memory was allocated at address %.8X\n", bpp);
}
When I use the small memory model, everything runs smoothly. The
problem is when I use the Large memory model. In this case the program
output is the following:
C:\BCTEST>tstmall
Memory was allocated at address 00000004
Memory was allocated at address 00000004
Every call to malloc returns exactly the same address (not null). I've
verified that the sizeof(BEAM_PROFILE * ) is 4 bytes with the large
memory model and 2 bytes with the small memory model, so I really
cannot figure out where the problem is...
Hope you have some clue about it...
Regards
Nicola