tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Caldarale, Charles R" <Chuck.Caldar...@unisys.com>
Subject RE: [OT] JNI problem
Date Thu, 08 Oct 2009 23:24:38 GMT
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: [OT] JNI problem
> 
> I saw the same thing at first glance, but then I looked-up the sizeof()
> operator and it seems that sizeof /can/ return the number of bytes in
> an array in C99

Minor correction: the operator is sizeof, not sizeof() - it is not a function.  The parentheses
one often sees with sizeof are either unnecessary (when used around a variable name) or a
*cast* operator, when used with a type.  The sizeof operator always returns the number of
bytes occupied by the type of the operand, which is the declared size, not any associated
dynamically allocated size.  For example:

char array[6];
char * ptr;
struct string {
  int len;
  char body[];
};
struct string sptr = malloc(sizeof (struct string) + 8);

sizeof array returns 6
sizeof ptr returns 4 or 8, depending on platform
sizeof (struct string) returns 4 (usually; sometimes 8) - the length of the int
sizeof sptr returns 4 or 8, depending on platform
sizeof *sptr returns the same as sizeof (struct string)

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus
for use only by the intended recipient. If you received this in error, please contact the
sender and delete the e-mail and its attachments from all computers.


Mime
View raw message