Compact C
Preprocessor chains, defines, early returns and conditional blocks without braces.
+ <stdio.h>
$ SQUARE(x) = ((x)*(x))
?+ _WIN32
$ PLATFORM = "Windows"
:# defined(__linux__)
$ PLATFORM = "Linux"
:
$ PLATFORM = "Other"
s Point
x,y: i32
f sum(a: *i32, n: i32) i32
total := 0
for i := 0; i < n; i++
if a[i] < 0
^
elif a[i] == 0
!
total += a[i]
< total
f main()
nums: i32[] = {1,2,-3,4,0,5}
result: i32 = sum(nums, 6)
?# defined(TEST)
if result > 5
puts(PLATFORM)
else
< 1
:
result = SQUARE(result)
while result > 7
result--
< result != 7
#include <stdio.h>
#define SQUARE(x) ((x)*(x))
#ifdef _WIN32
#define PLATFORM "Windows"
#elif defined(__linux__)
#define PLATFORM "Linux"
#else
#define PLATFORM "Other"
#endif
typedef struct Point Point;
struct Point {
int x,y;
};
int sum(int *a, int n) {
int total = 0;
for (int i = 0; i < n; i++) {
if (a[i] < 0) {
continue;
} else if (a[i] == 0) {
break;
}
total += a[i];
}
return total;
}
int main(void) {
int nums[] = {1,2,-3,4,0,5};
int result = sum(nums, 6);
#if defined(TEST)
if (result > 5) {
puts(PLATFORM);
} else {
return 1;
}
#else
result = SQUARE(result);
#endif
while (result > 7) {
result--;
}
return result != 7;
}
What it shows
preprocessor, layout