Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Definisanje strukutre u header fajlu

[es] :: C/C++ programiranje :: Definisanje strukutre u header fajlu

Strane: 1 2

[ Pregleda: 4368 | Odgovora: 22 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

milanche
San Francisco

Član broj: 2447
Poruke: 1200
*.hsd1.ca.comcast.net.



+1001 Profil

icon Re: Definisanje strukutre u header fajlu28.03.2012. u 15:32 - pre 146 meseci
Skoro sam imao istovetni problem sa GCC kompajlerom.

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)


pa da se koristi gde god bi se inace koristio sizeof(niz)/sizeof(element niza).


 
Odgovor na temu

rikelme

Član broj: 36179
Poruke: 87
*.com.

Sajt: www.bhg.rs


+14 Profil

icon Re: Definisanje strukutre u header fajlu29.03.2012. u 01:24 - pre 146 meseci
http://c-faq.com/decl/extarraysize.html
--
 
Odgovor na temu

Texas Instruments

Član broj: 227540
Poruke: 272
*.amres.ac.rs.



+61 Profil

icon Re: Definisanje strukutre u header fajlu29.03.2012. u 10:12 - pre 146 meseci
Rikelme uleće klizeći i rešava sve nedoumice. :)
Hvala svima na pomoći.
 
Odgovor na temu

[es] :: C/C++ programiranje :: Definisanje strukutre u header fajlu

Strane: 1 2

[ Pregleda: 4368 | Odgovora: 22 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.