[so] do{ ...} while(0);

Andrei Deftu andreideftu at yahoo.com
Wed May 7 16:34:14 EEST 2008


Macro-urile se folosesc doar cand:
- nu stii tipurile la compilare (de ex swap intre doua
primitive), un fel de template-uri weak din C++
- definesti constante float
- vrei sa produci cod usor de optimizat de compilator
(de ex macro-uri care se expandeaza la constante)
- cand vrei sa restrictionezi scope-ul unor variabile
referite (de ex cele definite local in functii)
- ai nevoie de macrouri predefinite: __LINE__,
__func__.. sau concatenari

Cam atat, sper ca nu am scapat nimic. In rest inline.

--- foxX <alex.mihaiuc at gmail.com> wrote:

> mai e un dezavantaj - erorile / warningurile de
> compilare de la
> macrouri, in general sunt extrem de greu de legat de
> oricare din cele
> 2 locuri posibile generatoare ale problemei -
> definitia de macro /
> utilizarea lui.
> 
> On Tue, May 6, 2008 at 6:10 PM, Razvan Deaconescu
> <razvand at cs.pub.ro> wrote:
> >
> > On Tue, 2008-05-06 at 14:16 +0300, foxX wrote:
> >  > inline void print_so_rules(const char *msg)  //
> c++; eroare cand msg e int
> >  > {
> >  >           puts(msg);
> >  >           puts("Only RD loves macros at all");
> >  > }
> >
> >  type-safety-ul este un dezavantaj mare al
> macro-urilor. Functiile inline
> >  si enum-urile sunt recomandate pentru a scapa de
> acest dezavantaj. Sunt,
> >  insa, situatii in care raman utile. Motiv pentru
> care sunt inca
> >  utilizate pe scara larga intr-un numar mare de
> aplicatii.
> >
> >  Quote: "The C Programming Language�A language
> which combines the
> >  flexibility of assembly language with the power
> of assembly language."
> >
> >  C is not an easy language, but ... oh ... the
> power! :-D
> >
> >
> >
> >  Razvan
> >
> >
> >  --
> >  This message has been scanned for viruses and
> >  dangerous content by MailScanner, and is
> >  believed to be clean.
> >
> >  _______________________________________________
> >  so mailing list
> >  so at cursuri.cs.pub.ro
> > 
> http://cursuri.cs.pub.ro/cgi-bin/mailman/listinfo/so
> >
> 
> 
> 
> -- 
> kthxbai
> _______________________________________________
> so mailing list
> so at cursuri.cs.pub.ro
> http://cursuri.cs.pub.ro/cgi-bin/mailman/listinfo/so
> 



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


More information about the so mailing list