2

I am learning "Programming languages principles" and there is a lot of information about stuff which make up a programming language . Unfortunately every material I came across until now has a lot of technical jargon involved and is very difficult to understand (Atleast for a beginner sincerely trying to understand the topic on his own by reading the material) .

Can anyone explain me the "Subscript binding and array categories" in general .. The classification says there are five kinds of arrays -
1.Static array
2.Fixed stack-dynamic array
3.Stack dynamic array
4.Fixed heap dynamic array
5.Heap dynamic array

This is what I could understand from the definitions (almost on every article on this topic I came across) .

Static array - subscript ranges are statically bound and storage allocation is static.
I understood that the space for the array is allocated in memory at compile time (before run time) .

Fixed stack-dynamic array - subscript ranges are statically bound, but the allocation is done at elaboration time during execution.
Now I didn't understand anything . What is meaning of the italicized phrases

Stack-dynamic array - the subscript ranges are dynamically bound, and the storage allocation is dynamic “during execution.” Once bound they remain fixed during the lifetime of the variable.
I dont understand what is meant by being 'bound' ?

I should be able to understand the remaining two definitions if I understand these three .

I know I am asking a lot .
Thanks :)

Here's a link I recently came across which I find useful for this topic . Anyone interested in this topic , check it out . :)

3
  • Could you try to describe what you think it means, in your own words, so we could confirm/deny or otherwise help you along in your thinking?
    – jcmeloni
    Mar 15, 2012 at 14:31
  • 1
    @jcmeloni Ya sure . :)
    – progammer
    Mar 15, 2012 at 14:32
  • The programming language I'm using most has thrown all these "programming language principles" away :-)
    – gnasher729
    Jan 18 at 12:28

3 Answers 3

6

To elaborate DeadMG's answer, it sounds like they mean:

  1. Static array: an array whose size is known, and whose storage is allocated, at compile time. In C, you might write at global (file) scope:

    int static_array[7];
    
  2. Fixed stack-dynamic array: you know the size of your array at compile time, but allow it to be allocated automatically on the stack (the size is fixed at compile time but the storage is allocated when you enter its scope, and released when you leave it)

    void foo()
    {
      int fixed_stack_dynamic_array[7];
      /* ... */
    }
    
  3. Stack dynamic array: you don't know the size until runtime, eg. C99 allows this:

    void foo(int n)
    {
      int stack_dynamic_array[n];
      /* ... */
    }
    
  4. Fixed heap dynamic array: same as the 2 except using explicit heap allocation

    int * fixed_heap_dynamic_array = malloc(7 * sizeof(int));
    
  5. Heap dynamic array: you can probably guess this:

    void foo(int n)
    {
      int * heap_dynamic_array = malloc(n * sizeof(int));
    }
    

Is this the same book as Concepts of Programming Languages? Because again, these aren't a useful classification of types, they only address the allocation mechanism. Once you pass any of these "different" things into a function, their classification under this scheme is irrelevant.

8
  • Robert.W.Sebesta Principles of programming languages . I thought its a nice book :/ . Thanks for explaining it so well . Ya,it would be nice if you elaborate others as well . :)
    – progammer
    Mar 15, 2012 at 15:45
  • @ Useless .. Yes it is !!
    – progammer
    Mar 16, 2012 at 11:51
  • I have few questions . Can you clear them :) ?
    – progammer
    Mar 16, 2012 at 12:24
  • 1
    The fixed bit just means you know the size is fixed, so 4 and 5 would be identical if you can prove n == 7 at compile time. Declaring globally or locally makes no real difference under this terminology.
    – Useless
    Mar 16, 2012 at 13:05
  • 1
    Yes - at the risk of repeating myself, this naming scheme is useless, non-orthogonal and omits many interesting properties. I wouldn't use it at all, ever; with the possible exception of understanding the rest of the book.
    – Useless
    Mar 16, 2012 at 13:17
0

The classification is wrong. They are all arrays, and of fixed size. The only thing that changes is the memory region where they are allocated, and sometimes, the fixed size doesn't need to be known until runtime. These are not type-changing properties. All of those things are the exact same thing- an array.

0

DeadMG's as useless said it very well . I just want to make it simple as per my knowledge, so I can contribute to society a little bit .

1)you know size, and you know values .

2)you know size but you don't know values .

3)you don't know size, and you don't know values .

4)you know size, so you want to create explicit heap allocation with size. You know through malloc but you don't know values .

5)you don't know size, but you want to create an explicit allocation to heap, and obviously you don't know values too.

Hope this reduces many ambiguities . Thanks to all .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.