[Info-vax] C... the only winning move is not to play...
VAXman- at SendSpamHere.ORG
VAXman- at SendSpamHere.ORG
Tue Feb 11 09:24:26 EST 2014
In article <ldcov9$3mn$1 at reader1.panix.com>, JohnF <john at please.see.sig.for.email.com> writes:
>{...snip...}
> More to the point (even though there's no longer any
>real point to deal with), yeah, yours is still more readable,
>but I'd assumed your actual situation involved a variable
>number of elements to be concatanated, whereby
>you'd need some kind of similar loop regardless.
One of the nicest things about dynamic string descriptors is that the RTLs
that will accept them will resize them as needed. So, for that STR$CONCAT
call, it's possible to:
STR$CONCAT(&my_dynstr_d, &str1_d, &str2_d, ... , strN_d, &my_dynstr_d);
... or ...
STR$CONCAT(&my_dynstr_d, &my_dynstr_d, &str1_d, &str2_d, ... , strN_d);
The first argument is the target string. Therefore, in the first example,
those various strings are prepended to the existing string in my_dynstr_d.
In the second example, those various strings are appended to my_dynstr_d.
I let the RTLs handle the string length computation and the "malloc()" and
"free()", in C-speak, making the code far cleaner.
One of the things I hate seeing in C code on VMS is (unless the callee is
expecting a string of exactly 255 bytes and you don't plan to do anything
else with it):
char buffer[255];
$DESCRIPTOR(buffer_d,buffer);
:
RTL$populate_descriptor(&buffer_d);
:
some C code possibly referencing buffer_d.dsc$a_pointer.
:
I let the RTL decide the buffer size needed and I let the RTL dynamically
allocate/reallocate it.
struct dsc$descriptor_s buffer_d = {0,DSC$K_DTYPE_T,DSC$K_CLASS_D,NULL};
:
RTL$populate_descriptor(&buffer_d);
:
some C code possibly referencing buffer_d.dsc$a_pointer.
:
And, even if it's a system service which will only accepts a fixed length
string descriptor of some length,...
struct dsc$descriptor_s dynstr_d = {0,DSC$K_DTYPE_T,DSC$K_CLASS_D,NULL};
:
STR$GET1_DX(&((unsigned short)255), &dynstr_d);
SYS$whatever(...,&dynstr_d),...);
:
The result can then be trimmed down by one of the STR$ RTLs and this string
descriptor can then be manipulated by any subsequent RTLs which do accept a
dynamic string descriptor.
:
STR$TRIM(&dynstr_d,&dynstr_d);
:
>> Anyway, your suggestion worked and for that I am grateful.
>Yeah, glad it helped. That other guy's (was it "hb"?) suggestion
>to just copy the correct header is probably the generally wiser
>solution, rather than embedding this silly-looking kludge into
>your application code. But whatever works.
The problem is that this code may, someday, be handed off to those for whom
it's been developed. They may not have mucked with header files to make it
work. And, who knows what will happen with a compiler update; it might re-
build the offending header.
[Note] Error checking should be added to your code if/when you use the RTLs
detailed herein.
--
VAXman- A Bored Certified VMS Kernel Mode Hacker VAXman(at)TMESIS(dot)ORG
Well I speak to machines with the voice of humanity.
More information about the Info-vax
mailing list