You are viewing a single comment's thread. Return to all comments →
Your welcome baba! It's a pleasure for me if i can help you ;).
As you know, #define is a word to word translator, i.e. if we write something like this:
#define
#define meysam unsigned #define pg int void main() { meysam pg name; }
the compiler translate it to this first:
#define meysam unsigned #define pg int void main() { unsigned int name; }
and then compile it. Now look at my macro:
#define FUNCTION(name,operator) inline void name(int ¤t, int candidate) {!(current operator candidate) ? current = candidate : false;}
On code editor of submit page, we have something like this:
FUNCTION(minimum, <) FUNCTION(maximum, >)
So as first example of this replay, compiler will translate this lines to this:
inline void minimum(int ¤t, int candidate) {!(current < candidate) ? current = candidate : false;} inline void maximum(int ¤t, int candidate) {!(current > candidate) ? current = candidate : false;}
Why? on #define we have FUNCTION(name, operator), so when we write FUNCTION(minimum, <) on editor, all name on
FUNCTION(name, operator)
FUNCTION(minimum, <)
name
will translated to minimum, and this is same for <.
minimum
<
Now we have
on top of main function and we can call it later.
main
Any question are welcome :).
Seems like cookies are disabled on this browser, please enable them to open this website
Preprocessor Solution
You are viewing a single comment's thread. Return to all comments →
Your welcome baba! It's a pleasure for me if i can help you ;).
As you know,
#define
is a word to word translator, i.e. if we write something like this:the compiler translate it to this first:
and then compile it. Now look at my macro:
#define FUNCTION(name,operator) inline void name(int ¤t, int candidate) {!(current operator candidate) ? current = candidate : false;}
On code editor of submit page, we have something like this:
So as first example of this replay, compiler will translate this lines to this:
Why? on
#define
we haveFUNCTION(name, operator)
, so when we writeFUNCTION(minimum, <)
on editor, allname
on#define FUNCTION(name,operator) inline void name(int ¤t, int candidate) {!(current operator candidate) ? current = candidate : false;}
will translated to
minimum
, and this is same for<
.Now we have
on top of
main
function and we can call it later.Any question are welcome :).