This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: compilation problem with g++ when volatile is used
- To: Ooi Boon Pin <bpooi at gintic dot gov dot sg>
- Subject: Re: compilation problem with g++ when volatile is used
- From: Nathan Sidwell <nathan at codesourcery dot com>
- Date: Thu, 24 Feb 2000 17:09:54 +0000
- CC: "'gcc-bugs at gcc dot gnu dot org'" <gcc-bugs at gcc dot gnu dot org>
- Organization: CodeSourcery, LLC
- References: <01570E7F8223D2119C9A00805F9A267C01BD5A2B@gexchange.gintic.gov.sg>
Ooi Boon Pin wrote:
> main()
> {
> int hello=0;
> (volatile) hello=1;
> }
> ANSI C++ forbidden variable with no type for the [(volatile) hello=1]
> statement. May I know how can I workaround this problem?
in c++ you cannot have a type without a specifier (int, short or whatever).
`volatile' is a type qualifier. You must say
(volatile int)hello
but that's not right in this case either, as old-style casts are not lvalues
unless the cast to type is a reference. (However gcc accepts it as an
extension IIR).
(volatile int &)hello = 1;
or more explicitly
static_cast<volatile int &> (hello) = 1
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org