Thread: Volatile, nested structs

  1. #1
    Registered User
    Join Date
    Mar 2009

    Volatile, nested structs

    I can't figure out why I get "warning: assignment discards qualifiers from pointer target type" when I do this:
    struct b_struct {
        int *data;
    static volatile struct a_struct {
        struct b_struct b;
        int data[10];
    } a;
    int main(void)
        volatile struct b_struct b; =; /* This line gives a warning. */
        return 0;

  2. #2
    Registered User
    Join Date
    Sep 2007
    1,012 is “volatile pointer to int”, is “array of volatile int” which turns into “pointer to volatile int”.

    That is, with the array of int, each int is volatile. With the pointer, the pointer itself is volatile.

  3. #3
    Registered User
    Join Date
    Mar 2009
    I thought volatile was treated the same way as const, i.e. this makes a "pointer to const int":
    const int *ptr;
    So this makes a "volatile pointer to int" and not a "pointer to volatile int"?
    volatile int *ptr;
    EDIT: Okay I got it. Putting volatile on the struct makes each variable volatile, which for pointers means that the actual pointer becomes volatile and not the data it points to.
    Last edited by Memloop; 03-28-2010 at 05:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested structs
    By adamantinex in forum C Programming
    Replies: 1
    Last Post: 09-14-2009, 01:13 AM
  2. nested structs
    By bandal27 in forum C Programming
    Replies: 26
    Last Post: 12-13-2008, 09:14 PM
  3. Nested structs
    By Sir Andus in forum C Programming
    Replies: 5
    Last Post: 11-28-2006, 10:31 AM
  4. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  5. Nested Structs
    By Monkey83 in forum C Programming
    Replies: 2
    Last Post: 09-15-2006, 11:03 AM