Typecasting VARCHAR structure fields in C

From: Jeffery Cann <jcann_at_fairway.com>
Date: 1998/02/12
Message-ID: <34E3374A.B0F83C47_at_fairway.com>#1/1


Greetings.

[Quoted] I have turned on compiler warnings on my C compiler. I have noticed [Quoted] that the call to strlen function (line 4) causes datatype convertion warnings from the C compiler.

1 VARCHAR operation[20];
2

3       strcpy("My string", operation.arr);
4       operation.len = strlen(operation.arr);


The Oracle Pro*C compiler forms the following struct for

the operation VARCHAR variable:

    struct {

          unsigned short len; 
          unsigned char arr[20]; 
     } operation;


The strlen function prototype is:

     typedef size_t unsigned int;
     size_t strlen(const char *);

It's obvious that the compiler is telling me that the return size of the strlen function call (unsigned int) is not the same size as the lvalue operation.len (unsigned short).

It would also seem that I can remedy this warning by typecasting the return value of strlen function call to match the size of operation.len;

     operation.len = (unsigned short*)strlen(operation.arr);

However, the compiler then tells me that I am using different levels of indirection.

Apparently, I don't understand some piece of this puzzle. If you have a suggestion, I would appreciate it.

Thanks.
Jeff

--
Fairway Systems, Inc.
jcann_at_fairway.com
Received on Thu Feb 12 1998 - 00:00:00 CET

Original text of this message