C

Function-like macros

Në shqip: Makrot si funksione

ShpjegimiSQ

#define KATROR(x) ((x) * (x)) duket si funksion, por paraprocesori thjesht zëvendëson tekstin. Pa kllapa shtesë, KATROR(1 + 2) jep 5 në vend të 9. Në C modern, preferohen funksionet inline.

EnglishEN

#define SQUARE(x) ((x) * (x)) looks like a function, but the preprocessor just replaces text. Without extra brackets, SQUARE(1 + 2) gives 5 instead of 9. In modern C, inline functions are preferred.

Si ta mendosh

Si „gjej dhe zëvendëso“ në Word: s'kupton kuptimin, vetëm ndërron shkronjat.

Lexoje në anglisht

Like Word's “find and replace”: it doesn't understand meaning, it just swaps letters.

Shembull kodic

#define KATROR_GABIM(x) x * x
#define KATROR(x) ((x) * (x))
KATROR_GABIM(1 + 2);   // 1 + 2 * 1 + 2 = 5
KATROR(1 + 2);         // 9

Terma të lidhur