-
June 8th, 2006, 04:16 PM
#1
(arg) < (char *)4096 ? 0 : strlen( arg )
can any tell me what the following statement means, here arg is a string, say: "foo".
(arg) < (char *)4096 ? 0 : strlen( arg )
thanks
especially this part: (arg) < (char *)4096
Last edited by deller; June 8th, 2006 at 04:19 PM.
-
June 8th, 2006, 04:41 PM
#2
Re: (arg) < (char *)4096 ? 0 : strlen( arg )
Well, technically, it's comparing (arg) to the value 4096 (casted to a char pointer). If arg is less then 4096, the whole expression will resolve to '0'; otherwise it will resolve to the length of arg (if arg is indeed a pointer to a character array).
Viggy
-
June 9th, 2006, 01:56 AM
#3
Re: (arg) < (char *)4096 ? 0 : strlen( arg )
Behavior is implementation-dependent, since mapping between integers and pointers, via reinterpret_cast, is implementation-defined.
Anyway, if it is under a Windows platform, and knowing that pointers under 0x400000 are not mapped to physical memory (thus accessing them do a segmentation fault), this strange code is perhaps due to someone which try to store different things in a pointer.
This arg pointer seems to be : Either a number/identifier in range [0,4096) or a character string.
This type of weird non-portable way to store either an identifier or a pointer is even used by the Win32 API with resource identifiers... With integers in range [0,65536)
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|