From: brennan AT news DOT rt66 DOT com (Brennan "The Rev. Bas" Underwood) Newsgroups: comp.os.msdos.djgpp Subject: Re: Possible bug/misfeature in GCC Date: 2 Feb 1997 16:16:20 -0700 Organization: Acid Brain Lines: 43 Distribution: world Message-ID: <5d3784$h37$1@mack.rt66.com> References: <32F1A438 DOT 5509 AT rangenet DOT com> NNTP-Posting-Host: mack.rt66.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <32F1A438 DOT 5509 AT rangenet DOT com>, Dan Hedlund wrote: >The following lines compile wrong with the -O3 option. > >unsigned char inportb (int port) >{ > unsigned char c; > asm ("inb %%dx, %%al" > : "=a" (c) > : "d" (port)); > return c; >} > >void main (void) >{ > while (inportb (0)); >} > >GCC reads a byte from port 0 only once, and then compars that byte to 0 >in an endless loop. Apparently GCC thinks the byte retrieved from the >port doesn't change. You need a 'volatile' on that asm there. i.e. extern __inline__ unsigned char inportb (unsigned short _port) { unsigned char rv; __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "d" (_port)); return rv; } That's from pc.h. Just #include and it'll be correctly handled. Brennan -- brennan AT rt66 DOT com | Ding-a-ding-dang my dang-a-long-ling-long. Riomhchlaraitheoir| Rasterfarian | -O