Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C, how do you declare the members of a structure as volatile?

Tags:

How do you declare a particular member of a struct as volatile?

like image 643
blak3r Avatar asked Jun 11 '09 06:06

blak3r


People also ask

How do you declare a volatile structure?

typedef struct{ volatile uint8_t bar; } foo_t; foo_t foo_inst; I recognize that declaring a pointer-typed variable as volatile (e.g. volatile uint8_t * foo) merely informs the compiler that the address pointed-to by foo may change, while making no statement about the values pointed to by foo.

What is volatile declaration in C?

C's volatile keyword is a qualifier that is applied to a variable when it is declared. It tells the compiler that the value of the variable may change at any time--without any action being taken by the code the compiler finds nearby.

What is volatile structure?

The volatile structure is a member of a non-volatile structure, a pointer to which is used to access a register.

Can we use volatile as a variable name in C?

A volatile keyword in C is nothing but a qualifier that is used by the programmer when they declare a variable in source code. It is used to inform the compiler that the variable value can be changed any time without any task given by the source code. Volatile is usually applied to a variable when we are declaring it.


1 Answers

Exactly the same as non-struct fields:

#include <stdio.h> int main (int c, char *v[]) {     struct _a {         int a1;         volatile int a2;         int a3;     } a;     a.a1 = 1;     a.a2 = 2;     a.a3 = 3;     return 0; } 

You can mark the entire struct as volatile by using "volatile struct _a {...}" but the method above is for individual fields.

like image 171
paxdiablo Avatar answered Sep 28 '22 19:09

paxdiablo