COMS 4995 Advanced Systems Programming

Index of 2024-1/code/13

Parent directory
Makefile
main.c
sum.c

Makefile

CC=gcc
CFLAGS=-g -Wall -O0 -fno-omit-frame-pointer -fno-stack-protector
LDFLAGS=-static

main: main.o sum.o

main.o sum.o:

.PHONY: clean
clean:
	rm -f *.o main

.PHONY: all
all: clean main

main.c

#include <stdio.h>

long sum_array(long *p, int n);

int main() {
    long a[5] = {0, 1, 2, 3, 4};
    long sum = sum_array(a, 5);
    printf("sum=%ld\n", sum);
}

sum.c

long sum(long a, long b) {
    return a + b;
}

long sum_array(long *p, int n) {
    long s = 0;
    for (int i = 0; i < n; i++) {
        s = sum(s, p[i]);
    }
    return s;
}