Another problem with GCC...

Etienne Fortin etienne.fortin at sensio.tv
Tue Nov 2 21:32:06 UTC 2004


Let's talk about another problem with GCC :) This time I suspect a
problem on my side, but I can't find it.

Can someone explain to me why the optimization engine of GCC destroy
code for line 166-167???????



 	148	/**
 	149	 * Extract the file length from an initialization
packet.
 	150	 */

 	151	static size_t YmodemExtractFileLength(YMODEM_PACKET*
packet)
 	152	{
 	153		int i;
 	154	
 	155		// Setup pointer and string length.
-	156		int namesize = strlen((char*)packet->data);
-	157		char* slen = (char*)packet->data + namesize + 1;
 	158		
 	159		// Compute file length.
-	160		int lensize = strlen(slen);
-	161		if(lensize == 0)
 	162			return 0;
 	163		int mult = 1;
 	164		int size = 0;
-	165		for(i = lensize-1;i >= 0;i--) {
 	166			size += (mult * (int)(slen[i]-'0'));
 	167			mult *= 10;
 	168		}
 	169		
 	170		return size;
 	171	}
 	172	
 	173	

Maybe it's too late, I drank to much coffee, that I didn't get enough
sleep last night... But to me, the code is perfectly legal but GCC, for
some reason, thinks that lines 166-167 are not useful at all... 

Etienne Fortin
Sensio




More information about the users mailing list