Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Pro*C VARCHAR unsigned char Problem
Phil wrote:
>
> VARCHAR is actually a struct that contains
> an unsigned char, but I'd rather not have to explicitly type cast each of
> these calls to (char *). Is there an easy
> way around this?
>
> Phil
> philr_at_ibm.net
Aha.. if you're going to use VARCHARs then you should have created a macro to do the job - something like
#define STRTOVAR(x,y) {strcpy(x.arr,y); x.len = strlen(x.arr)}
you can also do one for VARTOSTR and one for VARTOVAR then all you have to code is
STRTOVAR(array_variable_name, string_variable_name);
makes the code more legible, and you make less mistakes that way. Then,
when
the rules change, you just have to amend the macro to '(char *)x.arr'.
Also
if you're really smart you can add bounds checking to make sure you
don't blow
any string array lengths (aaagh - core dump). Take the plunge now and
convert your code!
My thanks go to Dave Edwards at EMC2 in the UK for that brilliant tip. Another lesson painfully learned.
Alan Wilson Help fight continental drift. ======================================================================Received on Tue Jan 21 1997 - 00:00:00 CST