switch project from cpp to c language since cpp has no benefits what so ever and only confuses everything

This commit is contained in:
mykola2312 2024-07-20 16:59:04 +03:00
parent c6be556d3e
commit bf3a0ece78
7 changed files with 22 additions and 47 deletions

View file

@ -3,23 +3,23 @@ SRC_DIR = src
OBJ_DIR = obj OBJ_DIR = obj
BIN_DIR = bin BIN_DIR = bin
CC = g++ CC = gcc
LD = ld LD = ld
CXXFLAGS = -Wall -I$(INC_DIR) CFLAGS = -Wall -I$(INC_DIR)
LDFLAGS = LDFLAGS =
BLACKJACK_SRC = main.cpp process.cpp BLACKJACK_SRC = main.c process.c
BLACKJACK_OBJ := $(addprefix $(OBJ_DIR)/,$(patsubst %.cpp,%.o,$(BLACKJACK_SRC))) BLACKJACK_OBJ := $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.o,$(BLACKJACK_SRC)))
BLACKJACK_SRC := $(addprefix $(SRC_DIR)/,$(BLACKJACK_SRC)) BLACKJACK_SRC := $(addprefix $(SRC_DIR)/,$(BLACKJACK_SRC))
BLACKJACK_DEPS = process.h BLACKJACK_DEPS = process.h
BLACKJACK_DEPS := $(addprefix $(INC_DIR)/,$(BLACKJACK_DEPS)) BLACKJACK_DEPS := $(addprefix $(INC_DIR)/,$(BLACKJACK_DEPS))
DUMMY_TARGET_SRC = dummy_target.cpp DUMMY_TARGET_SRC = dummy_target.c
DUMMY_TARGET_OBJ := $(addprefix $(OBJ_DIR)/,$(patsubst %.cpp,%.o,$(DUMMY_TARGET_SRC))) DUMMY_TARGET_OBJ := $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.o,$(DUMMY_TARGET_SRC)))
DUMMY_TARGET_SRC := $(addprefix $(SRC_DIR)/,$(DUMMY_TARGET_SRC)) DUMMY_TARGET_SRC := $(addprefix $(SRC_DIR)/,$(DUMMY_TARGET_SRC))
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CXXFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
blackjack: $(BLACKJACK_OBJ) $(BLACKJACK_DEPS) blackjack: $(BLACKJACK_OBJ) $(BLACKJACK_DEPS)
$(CC) $(LDFLAGS) -o $(BIN_DIR)/$@ $(BLACKJACK_OBJ) $(CC) $(LDFLAGS) -o $(BIN_DIR)/$@ $(BLACKJACK_OBJ)

View file

@ -1,15 +1,4 @@
#pragma once #ifndef __PROCESS_H
#define __PROCESS_H
#include <string> #endif
#include <optional>
#include <sys/types.h>
class Process
{
public:
Process(pid_t pid) : pid(pid) {}
static std::optional<Process> FindByName(std::string name);
private:
pid_t pid;
};

View file

@ -28,7 +28,7 @@ __attribute__((noreturn)) void slave2_job()
status("slave2"); status("slave2");
puts("[slave2] will do something each second"); puts("[slave2] will do something each second");
while (true) while (1)
{ {
__asm__("nop"); __asm__("nop");
sleep(1); sleep(1);
@ -40,13 +40,11 @@ __attribute__((noreturn)) void* slave3_job(void*)
status("slave3"); status("slave3");
puts("[slave3] will do something each second but in a thread"); puts("[slave3] will do something each second but in a thread");
while (true) while (1)
{ {
__asm__("nop"); __asm__("nop");
sleep(1); sleep(1);
} }
return NULL;
} }
int main() int main()

8
src/main.c Normal file
View file

@ -0,0 +1,8 @@
#include <unistd.h>
#include "process.h"
int main(int argc, char** argv)
{
return 0;
}

View file

@ -1,15 +0,0 @@
#include <iostream>
#include "process.h"
int main(int argc, char** argv)
{
auto proc = Process::FindByName("dummy_target");
if (proc) proc = proc.value();
else
{
fputs("process not found\n", stderr);
return 1;
}
return 0;
}

1
src/process.c Normal file
View file

@ -0,0 +1 @@
#include "process.h"

View file

@ -1,6 +0,0 @@
#include "process.h"
std::optional<Process> Process::FindByName(std::string name)
{
return {};
}