Quantcast
Channel: User Jeremy - Stack Overflow
Viewing all articles
Browse latest Browse all 46

Answer by Jeremy for ARM C++ compiler won't compile structure with volatile const member

$
0
0

I don't have access to the Keil compiler, but under g++ 7.4.0, this struct generates an error not where it is defined, but where an instance of it is instantiated.

i.e. The line

VAR_Type fred;

results in an error because the const member requires an initialiser (which, being a bitfield, cannot be specified as a default initialiser, and can therefore only be provided via a default constructor definition).

Are you instantiating this struct yourself? (At line 18, perhaps?)

If you are, and if you're doing so for a legitimate reason (e.g. for an in-memory copy of the hardware registers), there does seem to be a solution:

VAR_Type fred = { 0 };

compiles without error (at least using g++ 7.4.0). (Note that this initialises the struct via the first member of the union.)

[EDITED TO ADD: A minimal complete verifiable example including full compiler command line would make it a lot easier for people to help you.]


Viewing all articles
Browse latest Browse all 46

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>