Another problem with GCC...

Etienne Fortin etienne.fortin at sensio.tv
Wed Nov 3 13:22:57 UTC 2004


An update on that matter...

If I add "volatile" to the char* pointer declaration of slen (line 157),
then the optimization engine keeps line 166.

Why I must use volatile on the slen pointer is beyond my comprehension!
How can GCC assume that slen is constant?

Etienne Fortin
Sensio


-----Message d'origine-----
De : Etienne Fortin [mailto:etienne.fortin at sensio.tv] 
Envoyé : 2 novembre, 2004 16:32
À : rtems-users at rtems.com
Objet : Another problem with GCC...


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