aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cpp06/ex00/Makefile4
-rw-r--r--cpp06/ex00/main.cpp5
-rw-r--r--cpp06/ex01/Makefile4
-rw-r--r--cpp06/ex01/main.cpp41
-rw-r--r--cpp06/ex01/serialization.hpp11
-rw-r--r--cpp06/ex02/Makefile4
-rw-r--r--cpp06/ex02/main.cpp4
7 files changed, 23 insertions, 50 deletions
diff --git a/cpp06/ex00/Makefile b/cpp06/ex00/Makefile
index e0de1f1..f548628 100644
--- a/cpp06/ex00/Makefile
+++ b/cpp06/ex00/Makefile
@@ -6,14 +6,14 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/04/15 09:59:30 by charles #+# #+# #
-# Updated: 2020/12/13 16:00:15 by charles ### ########.fr #
+# Updated: 2020/12/14 10:53:21 by cacharle ### ########.fr #
# #
# **************************************************************************** #
NAME = convert
CXX = clang++
-CXXFLAGS = -std=c++98 -Wall -Wextra -Werror
+CXXFLAGS = -Wall -Wextra -Werror
SRC = main.cpp
OBJ = $(SRC:.cpp=.o)
diff --git a/cpp06/ex00/main.cpp b/cpp06/ex00/main.cpp
index a0ef7f8..b66ff4e 100644
--- a/cpp06/ex00/main.cpp
+++ b/cpp06/ex00/main.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/16 10:54:10 by charles #+# #+# */
-/* Updated: 2020/12/13 17:11:08 by charles ### ########.fr */
+/* Updated: 2020/12/14 10:53:10 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -58,6 +58,8 @@ bool is_float(std::string input)
{
if (input[input.length() - 1] != 'f')
return false;
+ if (input == "nanf" || input == "+inff" || input == "-inff")
+ return true;
if (input.find('.') == std::string::npos)
input.insert(input.length() - 1, ".0");
return is_double(input.substr(0, input.length() - 1));
@@ -120,7 +122,6 @@ int main(int argc, char **argv)
return 1;
}
-
if (CHAR_MIN <= x && x <= CHAR_MAX && !std::isnan(x) && !std::isinf(x))
{
char c = static_cast<char>(x);
diff --git a/cpp06/ex01/Makefile b/cpp06/ex01/Makefile
index fff9a9f..8702cc9 100644
--- a/cpp06/ex01/Makefile
+++ b/cpp06/ex01/Makefile
@@ -6,14 +6,14 @@
# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/11/18 09:31:16 by charles #+# #+# #
-# Updated: 2020/11/18 10:17:03 by charles ### ########.fr #
+# Updated: 2020/12/14 11:11:02 by cacharle ### ########.fr #
# #
# ############################################################################ #
NAME = serialization
CXX = clang++
-CXXFLAGS = -std=c++98 -Wall -Wextra -Werror
+CXXFLAGS = -Wall -Wextra -Werror
SRC = main.cpp
OBJ = $(SRC:.cpp=.o)
diff --git a/cpp06/ex01/main.cpp b/cpp06/ex01/main.cpp
index 3786106..616935d 100644
--- a/cpp06/ex01/main.cpp
+++ b/cpp06/ex01/main.cpp
@@ -6,7 +6,7 @@
/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/18 09:32:02 by charles #+# #+# */
-/* Updated: 2020/11/18 10:22:26 by charles ### ########.fr */
+/* Updated: 2020/12/14 11:14:11 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,23 +20,9 @@
#include "serialization.hpp"
-void generate_chars(char c[8])
-{
- char choices[] =
- {
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
- 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
- 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
- };
- for (int i = 0; i < 8; i++)
- c[i] = choices[rand() % (sizeof(choices) / sizeof(char))];
-}
-
void* serialize(void)
{
- RawData *d = new RawData;
+ Data *data = new Data;
static const char choices[] =
{
@@ -47,26 +33,18 @@ void* serialize(void)
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
};
size_t choices_len = sizeof(choices) / sizeof(char);
- for (int i = 0; i < 8; i++)
+ for (size_t i = 0; i < 8; i++)
{
- d->c1[i] = choices[rand() % choices_len];
- d->c2[i] = choices[rand() % choices_len];
+ data->s1.push_back(choices[rand() % choices_len]);
+ data->s2.push_back(choices[rand() % choices_len]);
}
- d->n = rand() % INT_MAX;
- return reinterpret_cast<void*>(d);
+ data->n = rand() % INT_MAX;
+ return reinterpret_cast<void*>(data);
}
Data* deserialize(void* raw)
{
- RawData *raw_data = reinterpret_cast<RawData*>(raw);
- Data *data = new Data;
-
- char tmp[9] = {'\0'};
- memcpy(tmp, raw_data->c1, 8 * sizeof(char));
- data->s1 = tmp;
- memcpy(tmp, raw_data->c2, 8 * sizeof(char));
- data->s2 = tmp;
- data->n = raw_data->n;
+ Data *data = reinterpret_cast<Data*>(raw);
return data;
}
@@ -93,8 +71,9 @@ int main()
<< ", n: " << std::setw(10) << data->n
<< ", s2: " << data->s2
<< std::endl;
- delete reinterpret_cast<RawData*>(raw);
delete data;
}
+
+ std::cout << "sizeof(Data) = " << sizeof(Data) << std::endl;
return 0;
}
diff --git a/cpp06/ex01/serialization.hpp b/cpp06/ex01/serialization.hpp
index 36a5434..a04d476 100644
--- a/cpp06/ex01/serialization.hpp
+++ b/cpp06/ex01/serialization.hpp
@@ -6,7 +6,7 @@
/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/18 10:22:17 by charles #+# #+# */
-/* Updated: 2020/11/18 10:22:35 by charles ### ########.fr */
+/* Updated: 2020/12/14 11:10:42 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,18 +15,11 @@
# include <string>
-struct RawData
-{
- char c1[8];
- int n;
- char c2[8];
-};
-
struct Data
{
std::string s1;
int n;
std::string s2;
-};
+} __attribute__((packed));
#endif
diff --git a/cpp06/ex02/Makefile b/cpp06/ex02/Makefile
index 8a8ffca..72c6dd1 100644
--- a/cpp06/ex02/Makefile
+++ b/cpp06/ex02/Makefile
@@ -6,14 +6,14 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/04/15 09:59:30 by charles #+# #+# #
-# Updated: 2020/11/18 09:22:44 by charles ### ########.fr #
+# Updated: 2020/12/14 10:53:41 by cacharle ### ########.fr #
# #
# **************************************************************************** #
NAME = identify_real_type
CXX = clang++
-CXXFLAGS = -std=c++98 -Wall -Wextra -Werror
+CXXFLAGS = -Wall -Wextra -Werror
SRC = main.cpp A.cpp B.cpp C.cpp Base.cpp
OBJ = $(SRC:.cpp=.o)
diff --git a/cpp06/ex02/main.cpp b/cpp06/ex02/main.cpp
index 86cd78f..28614ca 100644
--- a/cpp06/ex02/main.cpp
+++ b/cpp06/ex02/main.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/15 10:00:18 by charles #+# #+# */
-/* Updated: 2020/11/18 09:29:49 by charles ### ########.fr */
+/* Updated: 2020/12/14 11:17:03 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -114,10 +114,10 @@ int main()
for (int i = 0; i < 10; i++)
{
Base *b = generate();
- std::cout << "---" << std::endl;
identify_from_pointer(b);
identify_from_reference(*b);
delete b;
+ std::cout << "---" << std::endl;
}
return 0;