Last active
August 12, 2024 10:30
-
-
Save muaddib1971/01d40a57cf62014fbf775279a3220066 to your computer and use it in GitHub Desktop.
Makefiles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "file1.h" | |
#include <iostream> | |
void f1(){ | |
std::cout << "hello from file 1\n"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef FILE1 | |
#define FILE1 | |
void f1(); | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "file2.h" | |
#include <iostream> | |
void f2(){ | |
std::cout << "hello from file 2\n"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef FILE2 | |
#define FILE2 | |
void f2(); | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "file3.h" | |
#include <iostream> | |
void f3(){ | |
std::cout << "hello from file 3\n"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef FILE3 | |
#define FILE3 | |
void f3(); | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "file1.h" | |
#include "file2.h" | |
#include "file3.h" | |
#include <cstdlib> | |
#include <iostream> | |
int main(){ | |
f1(); | |
f2(); | |
f3(); | |
return EXIT_SUCCESS; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#targetname: prereqs | |
# command | |
all:files | |
files:file1.o file2.o file3.o main.o | |
g++ file1.o file2.o file3.o main.o -o files | |
file1.o:file1.cpp file1.h | |
g++ -Wall -Werror -std=c++14 -c file1.cpp | |
file2.o:file2.cpp file2.h | |
g++ -Wall -Werror -std=c++14 -c file2.cpp | |
file3.o:file3.cpp file3.h | |
g++ -Wall -Werror -std=c++14 -c file3.cpp | |
main.o:main.cpp file1.h file2.h file3.h | |
g++ -Wall -Werror -std=c++14 -c main.cpp | |
.PHONY:clean | |
clean: | |
rm -f file1.o file2.o file3.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#targetname: prereqs | |
# command | |
CC=g++ | |
all:files | |
OBJECTS = file1.o file2.o file3.o main.o | |
CXXFLAGS = -Wall -Werror -std=c++14 | |
files:$(OBJECTS) | |
$(CC) $(OBJECTS) -o files | |
%.o:%.cpp *.h | |
$(CC) $(CXXFLAGS) -c $< | |
.PHONY:clean | |
clean: | |
rm -f $(OBJECTS) files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
typedef void * operation (void*, void *); | |
void * intadd(void * a, void * b) | |
{ | |
*(int*)a += *(int*)b; | |
return a; | |
} | |
void * intsub(void * a, void * b){ | |
*(int*)a -= *(int*)b; | |
return a; | |
} | |
void * dbladd(void * a, void * b){ | |
*(double*)a += *(double*)b; | |
return a; | |
} | |
void * dblsub(void * a, void * b) { | |
*(double*)a -= *(double *)b; | |
return a; | |
} | |
void * perform(void* a, void* b, operation op) { | |
return op(a,b); | |
} | |
int main(void){ | |
int a,b; | |
a=3; | |
b=4; | |
std::cout << "3 + 4 is:"; | |
perform(&a,&b,intadd); | |
std::cout << a << std::endl; | |
a=3; | |
b=4; | |
std::cout << "3 - 4 is:"; | |
perform(&a,&b,intsub); | |
std::cout << a << std::endl; | |
double da, db; | |
da=3.3; | |
db=4.4; | |
std::cout << "3.3+4.4 is "; | |
perform(&da,&db,dbladd); | |
std::cout << da << std::endl; | |
da=3.3; | |
db=4.4; | |
std::cout << "3.3-4.4 is "; | |
perform(&da,&db,dblsub); | |
std::cout << da << std::endl; | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment