[clangd] add cmake files and guide for clangd usage

This commit is contained in:
2026-03-08 09:13:21 +03:00
parent 7eec2df5cd
commit 5ef9132b34
7 changed files with 70 additions and 45 deletions

View File

@@ -1,2 +1,2 @@
CompileFlags: CompileFlags:
Add: [-std=c23] CompilationDatabase: build

2
.gitignore vendored
View File

@@ -86,3 +86,5 @@ dkms.conf
*.out *.out
*.app *.app
.cache/
build/

9
CMakeLists.txt Normal file
View File

@@ -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)

View File

@@ -1,3 +1,13 @@
# practices # practices
Repository with code from practice sessions Repository with code from practice sessions
# 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
```

3
include/add.h Normal file
View File

@@ -0,0 +1,3 @@
#include <stdint.h>
int32_t add(int32_t a, int32_t b);

View File

@@ -0,0 +1,2 @@
add_executable(practice-1 main.c)
target_include_directories(practice-1 PRIVATE ${GLOBAL_INCLUDES})

View File

@@ -1,13 +1,13 @@
#include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
struct my_perfect_float struct my_perfect_float
{ {
unsigned char sign; unsigned char sign;
signed char exponent; signed char exponent;
unsigned char dop_var; unsigned char dop_var;
int mantissa; int mantissa;
}; };
// 1. вернуть объект с некорректными данными в нём // 1. вернуть объект с некорректными данными в нём
@@ -22,62 +22,61 @@ const int MANTISSA_SIZE = 24;
struct dm_e struct dm_e
{ {
struct dm result; struct dm result;
int error_code; int error_code;
}; };
struct dm struct dm
{ {
int32_t div; int32_t div;
int32_t mod; int32_t mod;
}; };
int divmod(int32_t x, int32_t y, struct dm* dm) int divmod(int32_t x, int32_t y, struct dm* dm)
{ {
int aa = 2; // initialization int aa = 2; // initialization
aa = 3; // assignment aa = 3; // assignment
int bb; // non-initialize int bb; // non-initialize
if (y == 0) if (y == 0)
{ {
return 1; return 1;
} }
*dm = (struct dm){ .div = x / y, .mod = x % y }; *dm = (struct dm){ .div = x / y, .mod = x % y };
return 0; return 0;
} }
// x, y => /, % // 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 int aa = 2; // initialization
aa = 3; // assignment aa = 3; // assignment
int bb; // non-initialize int bb; // non-initialize
if (y == 0) if (y == 0)
{ {
*error_code = 1; *error_code = 1;
return (struct dm) { .div = 0, .mod = 0 }; return (struct dm){ .div = 0, .mod = 0 };
} }
//struct dm dm = { .div = x / y, .mod = x % y }; // struct dm dm = { .div = x / y, .mod = x % y };
//return dm; // return dm;
return (struct dm){ .div = x / y, .mod = x % y }; // compound literal return (struct dm){ .div = x / y, .mod = x % y }; // compound literal
} }
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc != 4) if (argc != 4)
{ {
// free resourses // free resourses
fprintf(stderr, "Usage: %s A.B <rounding> <number>\n", argv[0]); fprintf(stderr, "Usage: %s A.B <rounding> <number>\n", argv[0]);
return 1; return 1;
} }
int32_t a, b; int32_t a, b;
int sz = 5; int sz = 5;
// .... 100 lines // .... 100 lines
int64_t c; int64_t c;
c = 2; c = 2;
return 0; return 0;
} }