Variably modified type

This is a discussion on Variably modified type within the C Programming forums, part of the General Programming Boards category; Hello to all Variably modified types are subject to certain restrictions , just as variable-length arrays are. The most important ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Location
    Athens , Greece
    Posts
    296

    Variably modified type

    Hello to all

    Variably modified types are subject to certain restrictions , just as variable-length arrays are. The most important restriction is that the declaration of a variably modified type must be inside the body of a function or in a function prototype

    Code:
    void f(int m , int n)
    {
    int a[m][n] , (*p)[n];
    
    p=a;
    
    //....
    }
    What does it mean? That we can't declare such a pointer as a global variable?

    Thank you in advance.

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,332
    That we can't declare such a pointer as a global variable?
    O_o

    Would you understand the reasons if it were a "VLA" instead of a "VMT"?

    How would you declare the variable `p' at global scope?

    Soma

  3. #3
    Registered User
    Join Date
    Sep 2011
    Location
    Athens , Greece
    Posts
    296
    Quote Originally Posted by phantomotap View Post
    O_o

    Would you understand the reasons if it were a "VLA" instead of a "VMT"?

    How would you declare the variable `p' at global scope?

    Soma
    I don't know... I just read this and I couldn't bring in my mind some example ... sorry

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Think of a VLA as a clever wrapper around malloc, and work out the contexts in which it is valid to call malloc.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Sep 2011
    Location
    Athens , Greece
    Posts
    296
    I think I got it. Variably modified types has the same restrictions as VLA's.

    So you can't declare a VLA outside a function because its dimensions are not known outside from this function.

    Code:
    #include<stdio.h>
    
    int main(void)
    
    {
    int n;
    
    printf("Give n : ");
    scanf("%d" , &n);
    
    int VLA[n]; // inside the function main ....
        
        return 0;
    }
    I think that is a simple reason...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can the some value of array be modified?
    By zcrself in forum C Programming
    Replies: 4
    Last Post: 11-26-2009, 09:22 PM
  2. modified
    By archriku in forum C Programming
    Replies: 3
    Last Post: 05-07-2009, 11:34 PM
  3. Date Last Modified
    By magic.mike in forum Windows Programming
    Replies: 5
    Last Post: 09-23-2005, 05:13 AM
  4. Last modified date?
    By Hoxu in forum C++ Programming
    Replies: 3
    Last Post: 11-15-2001, 11:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21