diff --git a/.clangd b/.clangd index 90826a8..5a804e9 100644 --- a/.clangd +++ b/.clangd @@ -1,2 +1,2 @@ CompileFlags: - Add: [-std=c23] \ No newline at end of file + CompilationDatabase: build \ No newline at end of file diff --git a/.gitignore b/.gitignore index acf5dd9..b6fd3f5 100644 --- a/.gitignore +++ b/.gitignore @@ -86,3 +86,5 @@ dkms.conf *.out *.app +.cache/ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2f05d79 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.20) +project(pracitces) + +set(CMAKE_C_STANDARD 23) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(GLOBAL_INCLUDES ${CMAKE_SOURCE_DIR}/include) + +add_subdirectory(practice-1) diff --git a/README.md b/README.md index 62d5141..64f7404 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ # practices +Repository with code from practice sessions -Repository with code from practice sessions \ No newline at end of file +# Clangd +First, build the project to generate `compile_commands.json`: +```bash +cmake -B build +``` +Then tell clangd where to find it by adding to `.clangd`: +```yaml +CompileFlags: + CompilationDatabase: build +``` \ No newline at end of file diff --git a/include/add.h b/include/add.h new file mode 100644 index 0000000..226b3e3 --- /dev/null +++ b/include/add.h @@ -0,0 +1,3 @@ +#include + +int32_t add(int32_t a, int32_t b); \ No newline at end of file diff --git a/practice-1/CMakeLists.txt b/practice-1/CMakeLists.txt new file mode 100644 index 0000000..85cb6c9 --- /dev/null +++ b/practice-1/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(practice-1 main.c) +target_include_directories(practice-1 PRIVATE ${GLOBAL_INCLUDES}) \ No newline at end of file diff --git a/practice-1/main.c b/practice-1/main.c index d0d3d0a..e1d70d9 100644 --- a/practice-1/main.c +++ b/practice-1/main.c @@ -1,13 +1,13 @@ -#include #include +#include #include struct my_perfect_float { - unsigned char sign; - signed char exponent; - unsigned char dop_var; - int mantissa; + unsigned char sign; + signed char exponent; + unsigned char dop_var; + int mantissa; }; // 1. вернуть объект с некорректными данными в нём @@ -22,62 +22,61 @@ const int MANTISSA_SIZE = 24; struct dm_e { - struct dm result; - int error_code; + struct dm result; + int error_code; }; struct dm { - int32_t div; - int32_t mod; + int32_t div; + int32_t mod; }; - int divmod(int32_t x, int32_t y, struct dm* dm) { - int aa = 2; // initialization - aa = 3; // assignment - int bb; // non-initialize - if (y == 0) - { - return 1; - } - *dm = (struct dm){ .div = x / y, .mod = x % y }; - return 0; + int aa = 2; // initialization + aa = 3; // assignment + int bb; // non-initialize + if (y == 0) + { + return 1; + } + *dm = (struct dm){ .div = x / y, .mod = x % y }; + return 0; } // x, y => /, % -struct dm divmod(int32_t x, int32_t y, int *error_code) +struct dm divmod(int32_t x, int32_t y, int* error_code) { - int aa = 2; // initialization - aa = 3; // assignment - int bb; // non-initialize - if (y == 0) - { - *error_code = 1; - return (struct dm) { .div = 0, .mod = 0 }; - } - //struct dm dm = { .div = x / y, .mod = x % y }; - //return dm; - return (struct dm){ .div = x / y, .mod = x % y }; // compound literal + int aa = 2; // initialization + aa = 3; // assignment + int bb; // non-initialize + if (y == 0) + { + *error_code = 1; + return (struct dm){ .div = 0, .mod = 0 }; + } + // struct dm dm = { .div = x / y, .mod = x % y }; + // return dm; + return (struct dm){ .div = x / y, .mod = x % y }; // compound literal } int main(int argc, char* argv[]) { - if (argc != 4) - { - // free resourses - fprintf(stderr, "Usage: %s A.B \n", argv[0]); - return 1; - } + if (argc != 4) + { + // free resourses + fprintf(stderr, "Usage: %s A.B \n", argv[0]); + return 1; + } - int32_t a, b; + int32_t a, b; - int sz = 5; - // .... 100 lines - int64_t c; + int sz = 5; + // .... 100 lines + int64_t c; - c = 2; + c = 2; - return 0; + return 0; }