Inital commit for udemy c++ course

master
Tibor Bizjak 2023-07-12 21:38:31 +02:00
parent d8252a8967
commit afc4c14e54
3 changed files with 31 additions and 0 deletions

8
.gitignore vendored
View File

@ -18,3 +18,11 @@
!k\&r/*/[0-9]*.c
# and header files
!k\&r/*/*.h
# ---- udemy c++ .gitignore ----
# except udemy cpp
!udemy-cpp/
# excpet chapters
!udemy-cpp/[0-9]*/
# except solutions
!udemy-cpp/*/[0-9]*.cc

View File

@ -1,3 +1,4 @@
# Solutions to varius excersises
Solutions to varius excersises from different sources.
- k&r - [The C Programming Language](https://en.wikipedia.org/wiki/The_C_Programming_Language)
- udemy-cpp - [Quick Start to Modern C++ for Programmers](https://www.udemy.com/course/quick-start-to-modern-c-for-programmers/)

View File

@ -0,0 +1,22 @@
#include <cstdint>
#include <cinttypes>
#include <iostream>
/* somewhat overcomplicated, could use macros provided by cstdint */
/* take advantage of two's complement */
#define INT_TEST(BITS) \
std::int##BITS##_t i##BITS = ~(~UINT##BITS##_C(0) << (BITS-1)); \
std::uint##BITS##_t u##BITS = -1; \
std::printf("%-10s %" PRId##BITS "\n", "int"#BITS"_t" , i##BITS); \
std::printf("%-10s %" PRIu##BITS "\n", "uint"#BITS"_t" , u##BITS)
#define BITS X(8) X(16) X(32) X(64)
/* prints sizes of varius (u)intX_t types */
int main()
{
std::cout << "max values of intx_t";
#define X(B) std::cout << '\n'; INT_TEST(B);
BITS
#undef X
}