access to a volatile variable
Sergei Organov
osv@Javad.RU
Wed Jun 30 23:07:00 GMT 1999
Nathan Sidwell <nathan@acm.org> writes:
> Sergei Organov wrote:
> >
> > Because, for example, *whole* struct might be single hardware register:
> >
> > struct A {
> > int i : 1;
> > int j : 1;
> > };
> I nearly put a comment about this, but figured that using bitfields to *access*
> volatile objects is so obviously insane that I needn't. (Notice I didn't say
> `using bitfields to *describe* the *layout* of a device register'.)
> Ho hum.
Maybe it is insane, but still it works fine for me.
>
> > A a = *pa; /* Access to structure as _whole_ */
> > int i = a.i;
> > int j = a.j;
> >
> > generates _one_ access to the hardware address (at least with all C
> > compilers I ever used)
> Prove that the language guarantees that. [a particular compiler on a particular
> system may offer such a guarantee by accident or by design, I'd even like an
> example of a compiler where this is a documented feature.]
I can't prove (and I'm almost sure it couldn't be proved), that's why
I didn't claim it does. But once I check that it works this way with
particular compiler for particular target, I use it, because it is so
hardware dependent and it is very unlikely that this code will ever be
compiled for another target or by another compiler.
> > Unfortunately the latter is not valid C++ :-( Have no idea why didn't
> Why is it not valid? (What do you mean by `valid' -- that it guarantees a
> single access, or that it is compilable without diagnostic?)
It requires constructor
A(A volatile&);
to be defined for struct A, to compile 'A a = *pa', but doesn't
provide such constructor automatically (the same for assignment
operator). So the code shouldn't compile. It is explicitly mentioned
in C/C++ incompatibilities section of the Standard. I posted it here
as egcs bug some time ago, but one of gurus explained me that I was
wrong.
>
> > they preserve compatibility with C in this area at least for
> > PODs. Don't you think it'd be fine idea to bypass this limitation in
> > egcs?
> What limitation?
To require to define 'A(A volatile&)' to compile (actually egcs
produces warning, not error).
>
> nathan
Sergei.
More information about the Gcc-bugs
mailing list