Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. while (*p++);

while (*p++);

Scheduled Pinned Locked Moved C / C++ / MFC
21 Posts 9 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Chintoo723

    With your solution p will point to the first NULL from the beginning, which is not really correct. it will point to the char after the first null. try to trace it and see. but be careful with the string you use, or your program might crash. for eg, use "a\0bb\0ccc\0\0dddd" I can understand, the code is very deceptive. only a few get it right the first time, and I am not one of them either :) thanks!

    J Offline
    J Offline
    John R Shaw
    wrote on last edited by
    #21

    Lets make it more accurate then:

    // UNOPTIMIZED
    //////////////////////////
    343: char* p = "123";
    0043CA51 mov dword ptr [ebp-14h],offset string "123" (004df014)
    344: while( *p++ ) {};
    0043CA58 mov eax,dword ptr [ebp-14h] // eax <- p
    0043CA5B movsx ecx,byte ptr [eax] // value_type = p[0];
    0043CA5E mov edx,dword ptr [ebp-14h] // edx <- p
    0043CA61 add edx,1 // edx <- edx + 1
    0043CA64 mov dword ptr [ebp-14h],edx // p <- edx
    0043CA67 test ecx,ecx // if( ecx is 0 )
    0043CA69 je main+4Dh (0043ca6d) // goto 0043CA6D
    0043CA6B jmp main+38h (0043ca58) // goto 0043CA51
    345: return 0;
    0043CA6D xor eax,eax
    0043CA6F jmp __tryend$_main$1+2Ch (0043cac0)

    // UNOPTIMIZED
    START_LOOP:
    value_type = *p;
    ++p;
    if( value_type == 0 )
    goto END_LOOP;
    goto START_LOOP;
    END_LOOP:

    INTP Every thing is relative...

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups