Skip to content

Commit

Permalink
Fix compilation (skip some)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolasan committed Sep 6, 2024
1 parent 44fdb25 commit 44fdbbd
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 23 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ Add to user environment variables

```
Lua51_ROOT = "C:\<path_to_cpp-skill>\windows\lua"
```


## Build

```
cmake -DCMAKE_BUILD_TYPE=Release -S . -B build
cmake --build build --target all
```
3 changes: 3 additions & 0 deletions basics/constness/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
add_executable(const-1 const-1.cpp)
add_executable(const-2 const-2.cpp)
add_executable(const-3 const-3.cpp)
add_executable(const-4 const-4.cpp)
add_executable(const-5 const-5.cpp)
4 changes: 2 additions & 2 deletions basics/constness/const-1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ int main(int argc, char const *argv[])
{
const char* const_variable = nullptr;
const_variable = new char[5];
const_variable[0] = 'H'; // error: expression must be a modifiable lvalue
delete const_variable;
// const_variable[0] = 'H'; // error: expression must be a modifiable lvalue
delete[] const_variable;
return 0;
}
4 changes: 2 additions & 2 deletions basics/constness/const-2.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
int main(int argc, char const *argv[])
{
char* const const_variable = nullptr;
const_variable = new char[5]; // error: expression must be a modifiable lvalue
// const_variable = new char[5]; // error: expression must be a modifiable lvalue
const_variable[0] = 'H';
delete const_variable;
delete[] const_variable;
return 0;
}
2 changes: 1 addition & 1 deletion basics/constness/const-3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ int main(int argc, char const *argv[])
const_variable[3] = 'l';
const_variable[4] = 'o';
delete const_variable;
const_variable = nullptr; // error: expression must be a modifiable lvalue
// cons[]t_variable = nullptr; // error: expression must be a modifiable lvalue
return 0;
}
6 changes: 3 additions & 3 deletions basics/constness/const-4.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
int main(int argc, char const *argv[])
{
const char* const const_variable = new char[5];
const_variable[0] = 'H'; // error: expression must be a modifiable lvalue
delete const_variable;
const_variable = nullptr; // error: expression must be a modifiable lvalue
// const_variable[0] = 'H'; // error: expression must be a modifiable lvalue
delete[] const_variable;
// const_variable = nullptr; // error: expression must be a modifiable lvalue
return 0;
}
4 changes: 2 additions & 2 deletions oop/destructor/protected-destructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class ProtectedDestructor {

int main(int argc, char const *argv[])
{
ProtectedDestructor* obj = new ProtectedDestructor();
const ProtectedDestructor* obj = new ProtectedDestructor();
// delete dynamic_cast<PleaseLetMeDelete*>(obj);
delete obj;
// delete obj; // error: destructor is inaccessible
return 0;
}
3 changes: 1 addition & 2 deletions oop/non_copyable/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# set(CMAKE_CXX_STANDARD 17)
add_executable(non-copyable non-copyable.cpp)
# add_executable(non-copyable non-copyable.cpp)
add_executable(func-in-derived-class func-in-derived-class.cpp)
add_executable(func-in-derived-2 func-in-derived-2.cpp)
2 changes: 1 addition & 1 deletion patterns/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_subdirectory(factory)
add_subdirectory(fsm)
# add_subdirectory(fsm)
1 change: 1 addition & 0 deletions rand/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ set(CMAKE_CXX_STANDARD 20)

add_executable(randomness_test randomness-test.c)
configure_file(decoded-20240131051421.bin ${CMAKE_CURRENT_BINARY_DIR}/decoded-20240131051421.bin COPYONLY)
target_link_libraries(randomness_test m)

add_executable(tony_rand lrand.c)
6 changes: 4 additions & 2 deletions rand/randomness-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ int main(int argc, char const *argv[])
fseek(f, 0, SEEK_END);
int size = ftell(f);
printf("found %d bytes in binary file\n", size);
if (size <= 0)
if (size <= 0) {
fclose(f);
return -1;
}

fseek(f, 0, SEEK_SET);

int8_t *values = malloc(size);
int8_t* values = (int8_t*)malloc(size);
fread(values, sizeof(int8_t), size, f);
fclose(f);

Expand Down
1 change: 1 addition & 0 deletions serialization/save-number.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <iostream>
#include <stdint.h>

#define MIN(a, b) ((a < b) ? a : b)

Expand Down
4 changes: 2 additions & 2 deletions serialization/write-number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <limits>
#include <string>

static char mem[100]
static char mem[100];

template<typename T>
void write_number(T v, uint8_t* b, size_t type_size)
{
Expand All @@ -19,7 +20,6 @@ void save_pulse_value_into_nvram(const std::string &file_name_prefix, int id, T
size_t size = sizeof(T) + 1;
uint8_t *data = static_cast<uint8_t*>(std::calloc(size, sizeof(uint8_t)));
write_number<T>(value, data, size);
write_file_async(file_name, size, (unsigned char *)data, true);
free(data);
}

Expand Down
2 changes: 1 addition & 1 deletion templates/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ add_subdirectory(enable_if)
add_subdirectory(variadic)

set(CMAKE_CXX_STANDARD 20)
add_executable(why why.cpp)
# add_executable(why why.cpp)
add_executable(good-enum good-enum.cpp)
9 changes: 4 additions & 5 deletions templates/variadic/variadic-template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ void cool_function(Hint hint, Ts... args) {
}
case Hint::COOL_THREE:
{
if constexpr ()
auto print_cool_three = [](const char* string, size_t size) {
std::cout << string;
};
std::cout << "COOL THREE: ";
print_cool_three(args...);
// auto print_cool_three = [](const char* string, size_t size) {
// std::cout << string;
// };
// print_cool_three(args...);
std::cout << std::endl;
break;
}
Expand Down

1 comment on commit 44fdbbd

@mikolasan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.