U gomili razlicitih kompajlera, sizeof() operator najcesce funkcionise u fazi kompajliranja
('at compile time'), pa u principu ima problem sa odredjivanjem velicine niza koji at compile
time nije razresen (tj. definisanjem da je 'extern' se naznacuje da postoji, a ko je tacno
u pitanju, odakle je rodom, kako se zove, da li je zenjen i ima li brkove...postaje kompletno
poznato tek u fazi linkovanja ('at link time')).
http://en.wikipedia.org/wiki/Sizeof
Citat:
It is the responsibility of the compiler's author to implement the sizeof operator in a way specific and correct for a given implementation of the language. The sizeof operator must take into account the implementation of the underlying memory allocation scheme to obtain the sizes of various datatypes. sizeof is usually a compile-time operator, which means that during compilation, sizeof and its operand get replaced by the result-value. This is evident in the assembly language code produced by a C or C++ compiler. For this reason, sizeof qualifies as an operator, even though its use sometimes looks like a function call. Applying sizeof to variable length arrays, introduced in C99, is an exception to this rule.
Ovaj problem se ne secam da sam mao sa VisualStudio kompajlerom, sto potvrdjuje
deo gornjeg citata da sizeof( ) moze da se implementira na razne nacine, a da je
najcesce compile-time operator.
Neko cross-platform ispravno resenje bi bilo da se u header-u definise nesto kao
Code:
#define BROJ_ELEMENATA_U_NIZU (3)
#define BROJ_ELEMENATA_U_NIZU (3)
pa da se koristi gde god bi se inace koristio sizeof(niz)/sizeof(element niza).