添加getSum

This commit is contained in:
2025-10-21 14:36:58 +08:00
parent 97d7d66548
commit 536b0146cc
4 changed files with 21 additions and 2 deletions

View File

@@ -19,5 +19,5 @@
}
},
"initializeCommand": "gdb -ex 'set confirm off' -ex quit", // 初始化GDB配置
"postAttachCommand": "make debug" // 假设你的Makefile有debug目标
"postAttachCommand": "make debug"
}

View File

@@ -4,7 +4,7 @@
include ./make.h
# 目标和源文件
TARGETS = fork execlp
TARGETS = fork execlp getSum
SOURCES = $(wildcard $(SRC_DIR)/*.c) # 找到所有的 .c 文件
OBJECTS = $(patsubst $(SRC_DIR)/%.c,%.o,$(SOURCES)) # 将 .c 替换为 .o
@@ -26,6 +26,9 @@ fork: fork.o
execlp: execlp.o
$(CC) -o execlp execlp.o
getSum: getSum.o
$(CC) -o getSum getSum.o
# 从 .c 文件编译生成 .o 文件
%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) $(COMMON_INCLUDE_DIRS) -c $< -o $@

BIN
getSum Executable file

Binary file not shown.

16
src/getSum.c Normal file
View File

@@ -0,0 +1,16 @@
#include <stdio.h>
int getSum(void)
{
int sum = 0;
for (int i = 1; i <= 100; ++i) {
sum += i;
}
return sum;
}
int main(void)
{
printf("%d\n", getSum());
return 0;
}