Can global arrays in C ++ Break Binary Compatibility?

Say the shared library contains the following lines:

const char* const arr[] =
{
  "one",
  "two",
  "three"
};

1) Can the application reference this library and use the symbol "arr"?

2) Is binary compatibility broken if a new element is added to the definition?

3) How about whether one of the string literals has changed?

4) Why (not)?

Cheers, Luke

+3
source share
4 answers

1) Yes

2) No

3) Not a problem

4) Why do you think otherwise?

+5
source

In both cases, binary compatibility is not interrupted.

C , .

, .

+5

arr , . , arr .

arr, : , , .

NULL, :

const size_t arrSize = sizeof(arr)/sizeof(char*);
+4

1) , , extern ( , const , , -;)).

2) , arr , . , , arr NULL-terminated, extern const unsigned arr_size = sizeof(arr) / sizeof(arr[0]).

3) . ; , .

4) , arr , .

+4

Source: https://habr.com/ru/post/1726536/


All Articles