Useless Type Error

I get the following error with the following code. I tried to find out where the problem is on Google, but I did not find anything useful.

Compiling /home/tectu/projects/resources/chibios/ext/lcd/touchpad.c In file included from /home/tectu/projects/resources/chibios/ext/lcd/touchpad.c:1:0: /home/tectu/projects/resources/chibios/ext/lcd/touchpad.h:17:1: warning: useless type qualifier in empty declaration [enabled by default] 

Here's the code from line 12 to line 17 from touchpad.h :

 volatile struct cal { float xm; float ym; float xn; float yn; }; 

And here is how I use this structure inside touchpad.c :

 static struct cal cal = { 1, 1, 0, 0 }; 

Can someone show me the light ?: D

+4
source share
6 answers

You will not get an error, just a warning.

And this applies to how you declare your struct cal : it is not mutable by itself; variability applies only to the definition of a particular variable.

So, in static struct cal cal your static struct cal cal variable is just static , but not volatile .

In this sense, a volatile declaration is, as a warning, useless.

+5
source

volatile as a qualifier can be applied to a specific instance of the structure.
You apply it to a type that is useless, and the compiler correctly points it out.

+7
source

volatile qualifies a variable, not a type.

Doing:

 static volatile struct cal { float xm; float ym; float xn; float yn; } cal; 

will be legal as:

 struct cal { float xm; float ym; float xn; float yn; }; static volatile struct cal cal; 
+6
source

The volatile keyword makes sense with an object. Not a type definition.

+5
source

The operation of volatile keys must be used with real variables that do not have a type definition.

0
source

You cannot attach a volatile qualifier to a struct declaration.

But, contrary to other answers, you really can use the volatile qualifier for types, but not for structs . If you use typedef , you can create volatile for the structure.

In the following example, Vol_struct is actually unstable, as in the poster question. But Vol_type will create mutable variables without additional qualifications:

 /* -------------------------------------------------------------------- */ /* Declare some structs/types */ /* -------------------------------------------------------------------- */ /* wrong: can't apply volatile qualifier to a struct gcc emits warning: useless type qualifier in empty declaration */ volatile struct Vol_struct { int x; }; /* effectively the same as Vol_struct */ struct Plain_struct { int x; }; /* you CAN apply volatile qualifier to a type using typedef */ typedef volatile struct { int x; } Vol_type; /* -------------------------------------------------------------------- */ /* Declare some variables using the above types */ /* -------------------------------------------------------------------- */ struct Vol_struct g_vol_struct; /* NOT volatile */ struct Plain_struct g_plain_struct; /* not volatile */ volatile struct Plain_struct g_vol_plain_struct; /* volatile */ Vol_type g_vol_type; /* volatile */ 
0
source

All Articles