Char str1[] = "I was here";
Char* str2 = "I was here";
Int16 size1 = sizeof("I was here");
Int16 size2 = strlen ("I was here");
Int16 size3 = sizeof (str1);
Int16 size4 = sizeof (str2);
Char msg[100];
StrPrintF (msg,
"size = %d, size2 = %d, size3 = %d, size4 = %d\n",
size1, size2, size3, size4);
DbgMessage (msg);
You should see 11, 10, 11, 4 output.
A string literal is always counted as the amount of space required. Hence
the str[] and sizeof("...") will be the same, which is StrLen("...") + 1.
Only if the variable is a Char* will it be 4, since the compiler has no way
of knowing the contents of what it might be pointing at.
Mark Hotopp
"Scott Erickson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Heres the deal... My app is using NetLib to make socket conections to a
> webserver. When using the simulator, everything worked fine. The data
> made it to the device, and i did what i needed to with the webpages data.
> No problems at all. But when i put it on the treo650, it would get hungup
> on the NetLibDmReceive() call. I did some testing and found
> this...sizeof("GET /mypage HTTP/1.0\r\n\r\n") and StrLen("GET /mypage
> HTTP/1.0\r\n\r\n") would return different values, StrLen() was one higher
> then sizeof(). this was the 4th arg of the NetLibSend() call. once i
> switched to StrLen() in that call, everything worked fine on the device.
> But then the simulator would hangup at the same place it did on the device
> with sizeof(). In the end, for some reason, i have to make that 4th arg
> sizeof() if im using the simulator, but i have to switch it to StrLen()
> (or sizeof()+1) if i want to run it on the device. Can anyone explain to
> me why this happens???
>
> --
>
>
> Scott Erickson
> Software Development Team, FB-4, Inc.
> [EMAIL PROTECTED]
>
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/