Skip to content

Instantly share code, notes, and snippets.

@EteimZ
Last active August 29, 2022 11:01
Show Gist options
  • Select an option

  • Save EteimZ/7ac55016772bde919520146f363cdb05 to your computer and use it in GitHub Desktop.

Select an option

Save EteimZ/7ac55016772bde919520146f363cdb05 to your computer and use it in GitHub Desktop.
Demonstrating how to use gnu make.
#include <stdio.h>
#include "ops.h"
int main(){
int x = 10;
int y = 5;
int valA = add(x, y);
int valS = sub(x, y);
int valM = mul(x, y);
int valD = div(x, y);
printf("x = 10, y = 5 \n\n");
printf("x + y = %i \n", valA );
printf("x - y = %i \n", valS );
printf("x * y = %i \n", valM );
printf("x / y = %i \n", valD );
return 0;
}
CC=gcc # compiler
all: mainapp
mainapp: main ops
$(CC) main.o ops.o -o prog
main:
$(CC) -c main.c
ops:
$(CC) -c ops.c
run:
./prog
clean:
rm *.o prog
int add(int x, int y){
return x + y;
}
int sub(int x, int y){
return x - y;
}
int mul(int x, int y){
return x * y;
}
int div(int x, int y){
return x / y;
}
// addition
int add(int x, int y);
// subtraction
int sub(int x, int y);
// multiplication
int mul(int x, int y);
// division
int div(int x, int y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment