-Cq: Propagate const and volatile Qualifiers for Structs

Group

LANGUAGE

Scope

Application

Syntax
  -Cq
  
  
Arguments

None

Default

None

Defines

None

Pragmas

None

Description

This option propagates const and volatile qualifiers for structures. That means if all members of a structure are constant, the structure itself is constant as well. The same happens with the volatile qualifier. If the structure is declared as constant or volatile, all members are constant or volatile.

Example

The source code in the following listing declares two structs, each of which has a const member.

Listing: Declaring Two structs


struct {
  const field;

} s1, s2;

void myfun(void) {

  s1 = s2; // struct copy

  s1.field = 3; // error: modifiable lvalue expected

}

In the above example, the field in the struct is constant, but not the struct itself. Thus the struct copy `s1 = s2' is legal, even if the field of the struct is constant. But a write access to the struct field causes an error message. Using the -Cq option propagates the qualification ( const) of the fields to the whole struct or array. In the above example, the struct copy causes an error message.