Advertisement

String help in C

Started by April 17, 2014 03:25 AM
11 comments, last by alvaro 10 years, 9 months ago


    for (size_t counter = 0; counter < strlen(randomString); ++counter);

Oh, now this might take time that grows quadratically with the length of the string, depending on how smart the compiler is.



    for (size_t counter = 0; counter < strlen(randomString); ++counter);

Oh, now this might take time that grows quadratically with the length of the string, depending on how smart the compiler is.

in release that should compile out, compilers are pretty good at seeing what is changing in a loop and what is not.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

Advertisement

    for (size_t counter = 0; counter < strlen(randomString); ++counter);


Oh, now this might take time that grows quadratically with the length of the string, depending on how smart the compiler is.

in release that should compile out, compilers are pretty good at seeing what is changing in a loop and what is not.


It's still good practice to write code so you don't have to trust the compiler to do something smart like that. In this case you just need to write
for (size_t counter = 0; randomString[counter] != '\0'; ++counter);

This topic is closed to new replies.

Advertisement