I've found an strange behaviour with stdio.strlen() function.
Please, see following self-explaining code:

/*
$ gcc --version
gcc (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu3)
$ uname -a 
Linux alumne-desktop 2.6.24-23-generic #1 SMP Mon Jan 26 00:13:11 UTC 2009 i686
GNU/Linux
 */
#include <stdio.h>
#include <string.h>
#define MAX_PARAULA (10)
int main() {
        char paraula[MAX_PARAULA];
        int i;

        paraula[0]='\0';

        int m = strlen(paraula);
        for (i = 0; i <= m - 1; i++) { 
                printf("(option I) should not enter i=%i\n", i);
        }

        for (i = 0; i < strlen(paraula); i++) {
                printf("(option II) should not enter i=%i\n", i);
        }

        for (i = 0; i <= strlen(paraula) - 1; i++) {
                printf("(option III) should not enter i=%i but it does!\n", i);
        }
        return 0;
}


-- 
           Summary: strlen() strange behaviour in for()
           Product: gcc
           Version: 4.2.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: iesmoises at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39479

Reply via email to