[Info-vax] calloc fails with access violation
sapienzaf
sapienza at noesys.com
Tue Aug 25 22:13:42 EDT 2009
On Aug 25, 4:23 pm, Jose Cuevas <jcue... at mac.com> wrote:
> I'll play with it more, and I will try the other suggestions also.
On Aug 25, 4:23 pm, Jose Cuevas <jcue... at mac.com> wrote:
> I'll play with it more, and I will try the other suggestions also.
Lastly, here is a trivial sample using descriptors.
$ type cobmain.cob
identification division.
program-id. cobmain.
data division.
working-storage section.
01 top_structure.
03 string_a pic x(24) value all 'A'.
03 string_b pic x(24) value all 'B'.
procedure division.
main-program section.
do-it.
call 'ccdescriptor' using by descriptor top_structure.
call 'ccdescriptor' using by descriptor string_a.
call 'ccdescriptor' using by descriptor string_b.
stop run.
$
$ type ccdescriptor.c
#include <stdio>
#include <string>
#include <descrip>
#include <stdlib>
int ccdescriptor (struct dsc$descriptor_s *str)
{
char *zro;
zro = calloc((str->dsc$w_length + 1), 1);
strncpy (zro, str->dsc$a_pointer, str->dsc$w_length);
printf ("Length=%d\n", str->dsc$w_length);
printf ("Value=%s\n", zro);
return 1;
}
$
$ r cobmain
Length=48
Value=AAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBB
Length=24
Value=AAAAAAAAAAAAAAAAAAAAAAAA
Length=24
Value=BBBBBBBBBBBBBBBBBBBBBBBB
More information about the Info-vax
mailing list