compilation problem with g++ when volatile is used

Nathan Sidwell nathan@codesourcery.com
Thu Feb 24 09:13:00 GMT 2000


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


More information about the Gcc-bugs mailing list