Skip to content

Instantly share code, notes, and snippets.

@certik
Created July 20, 2011 23:22
Show Gist options
  • Select an option

  • Save certik/1096168 to your computer and use it in GitHub Desktop.

Select an option

Save certik/1096168 to your computer and use it in GitHub Desktop.
// Compile with:
// gcc -O3 -march=native -ffast-math -funroll-loops b.c
#include "stdio.h"
long sumit(long n)
{
long i = 0, s = 0;
while (i < n) {
s += i;
i++;
}
return s;
}
typedef long (*fn_ptr)(long);
long apply(fn_ptr f, long a)
{
return f(a);
}
int main(int argc, char *argv[])
{
long i = 0, sum = 0;
if (argc != 3) return 1;
long a, b;
a = atoi(argv[1]);
b = atoi(argv[2]);
fn_ptr s = sumit;
while (i < a) {
sum += apply(s, b);
i++;
}
printf("%ld\n", sum);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment