Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: Volatile modifier

2012-04-17 by bayramdavies

In AVR-Chat@yahoogroups.com, Don Kinzer wrote:

> For most languages, C included, it is conceptually
> easy [to determine whether or not a function modifies
> a global variable]: look at a function and see what
> global variables it might modify and then do the same
> for any function that it might call and so on.

But, doesn't a C compiler, by the very design of the language, limit itself to the consideration of a single translation unit at a time?  That would mean that if a called function is in a different unit there is no way of knowing what global variables are touched.  And, if the variable *isn't* modified by a function in a different unit, why would it be "global" in the first place?

> ... there are situations that complicate matters (e.g.
> writing through a pointer having an unknown value).  

So, even if the function is in the same unit, if it writes through a pointer the compiler again has to throw up its hands.  (This applies to file-scope variables, too.)

> If you compile the example code below ...

I wonder if the inlining is done first, in which case the optimization is unremarkable.

Graham Davies
ECROS Technology
www.ecrostech.com

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.