Re: Strange code in 2.0.pre35 - apricot.c

sinster@darkwater.com
Sun, 12 Jul 1998 01:48:06 -0700 (PDT)


Sprach ford@omnicron.com (Mike "Ford" Ditto):
> > register int hold;
> > do {
> > hold = lp->scb.status;
> > } while (lp->scb.command);
> > The 'hold' variable is needed in both cases to prevent the optimizer
> > from dropping the first clause, because some compilers don't [ ... ]
>
> No, it's not. The assignment to hold is not any stronger of a reference
> to scb.status than is an unsaved reference, and the above code is not
> reliable, since the compiler is free to completely optimize away both
> the reference to scb.status and the hold variable itself.
>
> scb.status must be declared volatile if reading it has desirable side
> effects, as is presumably the case in the original "strange" code. The
> volatile keywoard does guarantee that references are not optimized away
> even if the compiler can't see what purpose they have.

Admittedly the behavior of GCC is more important to us than Borland, but
Borland will often optimize 'volatile' accesses away, but it won't
optimize the above access away. Just be aware that broken optimizers
are out there and (from my experience) are far more common than working
optimizers. My experience is that 'volatile' is the least likely keyword
in C to be implemented correctly by any particular compiler.

-- 
Jon Paul Nollmann ne' Darren Senn                      sinster@balltech.net
Unsolicited commercial email will be archived at $1/byte/day.
co es agradable que me esten molestando todo el dia cuando yo jamas me
inscribi en su mail-list, cuando trato de que me quiten de su lista, todos
ustedes se la pasan insultandome incluido usted, no quiero que me manden
mas mails, esta manana tenia 194 mails que no me interesan y no solicite
este es mi lugar de trabajo y no estoy jugando como vosotros.
                                                  Fabian Casagni, 27/5/1998

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html