Specifying char array size in extern expression for sizeof command

Was

char B[200];

in the static library. He was referred to as

extern char B[];  // (1)

in the header, which is included in the client code. As soon as I needed to use sizeof(B), the compiler complained and changed to

extern char B[200]; // (2)

disabled the compiler.

The library and client code is C ++, but it uses C linkage (header header declarations surrounded by

extern "C" { ... }

Is there a potential problem if I use (2) instead of (1)?

PS I put 200 for simplicity. it is a constant defined in the header file that comes with the library.

:

#define MAXLEN 200

In fact, even if it is not a library, but in a separate file (compilation unit) the problem is similar.

Is there a way that (1) could be used in this big old code that I could break using (2)?

+3
2

- B, , , . , . , , sizeof(b), .

+9

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


All Articles