Can volatile be added through declarations

L

lovecreatesbea...

Can type qualifiers be added through declarations


For example, I have one variable defined in file scope without type
qualifier. In another file, say f1.c, this variable is declared with
two qualifiers added, and in the third file f2.c, declared with only
one qualifier added.

Will the variable act just as what they are declared in each file? Is
it a const and volatile variable in f1.c and only volatile in f2.c?



/* definition.c
***************************************************************/
/*no qualifier added*/
int g_value = 0;


/* f1.c
***********************************************************************/
int f1(void)
{
/*two qualifiers added: volatile, const*/
extern int volatile const g_value;

/*...*/
return 0;
}


/* f2.c
***********************************************************************/
int f2(void)
{
/*one qualifiers added: volatile*/
extern int volatile g_value;

/*...*/
return 0;
}



Thank you for your time.
 
E

Eric Sosman

Can type qualifiers be added through declarations


For example, I have one variable defined in file scope without type
qualifier. In another file, say f1.c, this variable is declared with
two qualifiers added, and in the third file f2.c, declared with only
one qualifier added.

Will the variable act just as what they are declared in each file? Is
it a const and volatile variable in f1.c and only volatile in f2.c?

The behavior is undefined.

6.7.3p9: "For two qualified types to be compatible,
both shall have the identically qualified version
of a compatible type [...]"

6.2.7p2: "All declarations that refer to the same
object or function shall have compatible type;
otherwise, the behavior is undefined."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top