Anonymous <no******@here.comwrites:
I need to refresh my memory on this one.
If have a struct defined like this:
typedef struct
{
char guid[32] ;
char version ;
char srcId ;
char eventId ;
char * msg ;
} MyStruct ;
is the size given by :
msg ? sizeof(MyStruct) + strlen(msg) : sizeof(MyStruct)
As Chris said, the size of the struct is sizeof(MyStruct).
If msg points to a string, the size of the array containing the string
must be at least strlen(msg) + 1 -- but the string could easily be
contained in a much larger array.
Or msg might not point to a string at all. Without seeing the code
that sets it, we have no way of knowing whether msg points to a
string, to a single character, to an array that may not contain any
'\0' characters, to an array that may contain multiple '\0'
characters, or to nothing at all.
You're asking about "the size". The size of *what*? Without knowing
that, the answer is unknowable. If we do know that, the answer is
likely to be trivial -- but if it depends on the size of the object to
which msg points, there's no direct way to determine that from the
value of msg.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"