Can volatile be added through declarations

Discussion in 'C Programming' started by lovecreatesbea...@gmail.com, Dec 11, 2007.

  1. Guest

    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.
     
    , Dec 11, 2007
    #1
    1. Advertising

  2. Eric Sosman Guest

    wrote:
    > 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."

    --
    Eric Sosman
    lid
     
    Eric Sosman, Dec 11, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bennett Haselton
    Replies:
    1
    Views:
    526
    John M Deal
    Nov 8, 2004
  2. Daniel

    Can volatile be trusted?

    Daniel, Sep 11, 2003, in forum: Java
    Replies:
    7
    Views:
    479
    Chris Uppal
    Sep 12, 2003
  3. ben
    Replies:
    5
    Views:
    605
    Ulrich Eckhardt
    Jan 11, 2005
  4. Frederick Gotham

    Can't work with volatile objects?

    Frederick Gotham, Aug 18, 2006, in forum: C++
    Replies:
    1
    Views:
    320
  5. Robert Oschler
    Replies:
    1
    Views:
    232
    Mcginkel
    Sep 5, 2005
Loading...

Share This Page