CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006
    Posts
    7

    (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.

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    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

  3. #3
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    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
  •  





Click Here to Expand Forum to Full Width

Featured