Skip to content

Commit

Permalink
Added object relocations
Browse files Browse the repository at this point in the history
  • Loading branch information
fzakaria committed Feb 19, 2024
1 parent a886a09 commit f0039db
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/object-relocations/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Variables
CC = gcc
CFLAGS = -Wall -g
TARGET = exe

# Default rule
all: $(TARGET)

$(TARGET): main.c sum.o
$(CC) $(CFLAGS) -o $(TARGET) main.c sum.o

sum.o: sum.c sum.h
$(CC) $(CFLAGS) -c sum.c


.PHONY: clean
clean:
rm -f $(TARGET) sum.o
11 changes: 11 additions & 0 deletions examples/object-relocations/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdio.h>

#include "sum.h"

int array[4] = {1, 2, 3, 4};

int main() {
int val = sum(array, 4);
printf("Sum: %d\n", val);
return 0;
}
9 changes: 9 additions & 0 deletions examples/object-relocations/sum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


int sum(const int* array, int size) {
int sum = 0;
for (int i = 0; i < size; i++) {
sum += array[i];
}
return sum;
}
3 changes: 3 additions & 0 deletions examples/object-relocations/sum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


int sum(const int* array, int size);

0 comments on commit f0039db

Please sign in to comment.