[ create a new paste ] login | about

Link: http://codepad.org/tmUhySJ8    [ raw code | output | fork | 1 comment ]

joshua_cheek - C, pasted on Nov 19:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>

int is_greater_than_20 ( int x ){  printf( "FIRST\n"  ); return x > 20 ; }
int is_less_than_30    ( int x ){  printf( "SECOND\n" ); return x < 30 ; }

#define and(a,b) ({a ? b : 0;})

int main(int argc, char **argv)
{
  int age ;
  for( age = 15 ; age < 40 ; age += 10 )
    if(  and( is_greater_than_20(age) , is_less_than_30(age) )  )
      printf( "%d: true\n\n" , age );
    else
      printf( "%d: false\n\n" , age );
  return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
FIRST
15: false

FIRST
SECOND
25: true

FIRST
SECOND
35: false



Create a new paste based on this one


Comments:
posted by joshua_cheek on Nov 19
Showing that we can achieve SCE using the NOE of a macro, whereas the AOE of a function call would not be able to achieve this.
reply