-1

I know that there are variables' names and functions' names in symbol table, but what about arrays? Are there arrays in symbol table?

n 1 k z z z
  • 109
  • 4
  • 4
    Aren't arrays variables? – NathanOliver May 03 '21 at 15:18
  • I don't believe standard c++ mentions anything about a symbol table. You may want to mention your compiler. – drescherjm May 03 '21 at 15:22
  • @NathanOliver, array is ordered set of variables, isn't it? – n 1 k z z z May 03 '21 at 15:22
  • I won't rely on it anyway, your compiler is free to include those names or not, depending on its implementation and its optimization level. Maybe if you could explain what you're trying to achieve... – YSC May 03 '21 at 15:22
  • What do you mean? Can't find "*symbol table*" in the C Standard (don't have a C++ Standard to search in)... – pmg May 03 '21 at 15:22
  • 1
    An array is not a set of variables. – drescherjm May 03 '21 at 15:24
  • 1
    An array is a collection of N objects in contiguous space. That doesn't mean it itself can't be a variable. – NathanOliver May 03 '21 at 15:24
  • @pmg, i am talking about this [symbol table](https://stackoverflow.com/questions/69112/what-is-a-symbol-table) – n 1 k z z z May 03 '21 at 15:25
  • A symbol table is an implementation detail. Neither the `c` language nor the `c++` language mention the existence of a symbol table in the standard. Meaning a question of the specifics is a compiler dependent – drescherjm May 03 '21 at 15:26
  • Have you read the accepted answer? _"There are two common and related meaning of symbol tables here."_ Assuming you mean the symbol table in a object file: _" Usually, a C or C++ compiler compiles a single source file into an object file with a .obj or .o extension."_ Which symbol table do you mean? The symbol table in an object file depends on your compiler. –  May 03 '21 at 15:27
  • @jabaa, i mean object file symbol table – n 1 k z z z May 03 '21 at 15:30
  • 1
    _"The symbol table in an object file depends on your compiler."_ Which compiler do you use? –  May 03 '21 at 15:30
  • @jabaa, i use msvc, but i think that there is something like symbol table in any compilier – n 1 k z z z May 03 '21 at 15:34
  • ***i think that there is something like symbol table in any compilier*** That may be true but the `c++` standard does not mention the existence or how a symbol table should be designed. A compiler is free to implement it if and how they want. – drescherjm May 03 '21 at 15:44

1 Answers1

2

An array can be just a regular variable: If you declare your array as a global variable (or a static variable) outside of any function definition like:

int myArray[256]; 

then yes, the name of the global variable is in the symbol table, as any global variable.

If you declare it in a function:

int myFunction(void) {
    int myArray[256];
    ...
}

Then, it reserves space on the stack of the current thread and it's treated as a local variable.

An array, in C, is just the constant address of the first element of a reserved space that can contain up to N elements of the same type.