0

There is a C- code
char* str = NULL; str = (char*) malloc(sizeof(char)*50);

Could I write the same thing in Cobol-85?

Or maybe I can use
01 LE USAGE IS POINTER.
pass it into C-lang function and allocate memory and fill string there and use this pointer on Cobol side for displaying string content? Like

call CFUNC using
by reference LE   
by descriptor "TEST STRING"  
giving LE.  
display LE.
Anton Golovenko
  • 634
  • 4
  • 19
  • On an unrelated note, that C code is not very nice. First of all, why initialized `str` with `NULL` to begin with? Why not initialize it by calling `malloc` directly in the definition of `str`? Also, `sizeof(char)` is specified to *always* be equal to `1`, so you never need to multiply with it. And lastly in C you [don't need to cast the result of `malloc`](https://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc-and-do-i-pass-the-size-of-the-type-or-the-object). – Some programmer dude Feb 03 '22 at 11:35
  • @Someprogrammerdude Thanks for your answer, but the question was about another thing. What about casting, etc. it is necessary on the Alpha OpenVMS platform because of local compiler specific. – Anton Golovenko Feb 03 '22 at 11:41
  • @AntonGolovenko Which compiler are you using? The dynamic allocation of memory is not something universally supported or even standardized. – Scott Nelson Feb 04 '22 at 14:03

0 Answers0