Lets have the files with the following contents:
file1.cpp: double array[100];
file2.cpp (client of file1.cpp):
/// What the difference between this:
extern double* array;
/// and this?
extern double array[];
If I use array declared in the first way I receive segfault. If second, it works ok. It confuses me, since in a regular C++ programm I can easily do the following and these objects would be equal:
double array[100];
double* same_array = array;
/// array[0] is equal to same_array[0] here
/// But why they are not equal in the example with extern?
The difference is that first is an pointer to the type double
and second is an array of double.
Important thing to note here is:
Arrays are not Pointers!
An expression with array type (which could be an array name) will convert to a pointer anytime an array type is not legal, but a pointer type is.
As per the rule mentioned,In above the array name decays in to a pointer to its first element.
Why does your program crash?
An array declaration creates an array which occupies some memory depending on the storage class(where is declared).
While a pointer just creates an pointer which points to some address. You would explicitly need to made it point to some valid object to be able to use it.
This should be a good read:
How do I use arrays in C++?