Forum: Compiler & IDEs Bedingte Übersetzung in macro packen, wie?


von Jürgen W. (coffeejunk)


Lesenswert?

Hallo,

wie kann ich folgendes in ein macro oder ähnliches packen:
1
#if (F_CPU > 4000000)
2
 asm volatile ("nop");
3
#endif
4
#if (F_CPU > 8000000)
5
 asm volatile ("nop");
6
#endif

Folgendes funktioniert leider nicht:
1
#define testnop() \
2
#if (F_CPU > 4000000) \
3
 asm volatile ("nop");\
4
#endif \
5
#if (F_CPU > 8000000) \
6
 asm volatile ("nop"); \
7
#endif \

Gibt es bei gcc soetwas wie #BeginMacro #ExitMacro ?

Jürgen

von Roland P. (pram)


Lesenswert?

Vielleicht so:
1
#ifdef (F_CPU > 4000000)
2
#define testnop()  asm volatile ("nop");
3
#endif

Gruß
Roland

von Nico E. (masta79)


Lesenswert?

Da ich kein Freund von Macros bin, würde ich es einfach so machen:

inline testnop(void) {
  if (F_CPU > 4000000)
    asm volatile ("nop");
  if (F_CPU > 8000000)
    asm volatile ("nop");
};

Mit -Os sollte der gcc das inlinen und da F_CPU fest ist wird er die 
Abfragen entsprechend wegoptimieren.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.