Skip to content

Commit

Permalink
fix: pequenos fix em tipos
Browse files Browse the repository at this point in the history
  • Loading branch information
igormcoelho committed Sep 4, 2023
1 parent fec01ca commit 082e0ad
Show file tree
Hide file tree
Showing 7 changed files with 571 additions and 528 deletions.
134 changes: 61 additions & 73 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,7 @@
#FROM mcr.microsoft.com/devcontainers/cpp:0-debian-11
FROM mcr.microsoft.com/devcontainers/cpp:0-ubuntu-22.04

ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none"

# Optionally install the cmake for vcpkg
COPY ./reinstall-cmake.sh /tmp/

RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
fi \
&& rm -f /tmp/reinstall-cmake.sh

# [Optional] Uncomment this section to install additional vcpkg ports.
# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install <your-port-name-here>"

# [Optional] Uncomment this section to install additional packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install \
texlive texlive-base texlive-latex-extra texlive-latex-recommended \
texlive-bibtex-extra biber \
texlive-xetex texlive-fonts-extra \
texlive-science \
texlive-lang-portuguese

# install rust
RUN curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | bash -s -- -y

# pandoc 2.19.2
RUN wget https://github.com/jgm/pandoc/releases/download/2.19.2/pandoc-2.19.2-1-amd64.deb
RUN sudo dpkg -i pandoc-2.19.2-1-amd64.deb

# pandoc-crossref 0.3.13
RUN wget https://github.com/lierdakil/pandoc-crossref/releases/download/v0.3.13.0b/pandoc-crossref-Linux.tar.xz
RUN mv pandoc-crossref-Linux.tar.xz /usr/local/bin/
RUN (cd /usr/local/bin/ && tar xf pandoc-crossref-Linux.tar.xz)

# install pandoc-katex
RUN bash -c 'source ~/.cargo/env; cargo install pandoc-katex'
# REFRESH!
RUN apt-get update && apt-get upgrade -y && apt-get autoremove -y

# install pip (for cpplint and cmake)
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
Expand All @@ -53,56 +15,82 @@ RUN pip install --upgrade cmake
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends software-properties-common

# gcc-12
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends g++-12 gcc-12

# clangd, clang-format and clang-tidy (standard)
#RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends clang-tidy clang-format clangd

# clang-16
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
RUN echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main" >> /etc/apt/sources.list
RUN echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main" >> /etc/apt/sources.list
# clang newer
#RUN bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
RUN curl --proto '=https' --tlsv1.2 https://apt.llvm.org/llvm.sh -sSf | bash -s -- -y

# clangd, clang-format and clang-tidy
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends clang-tidy-16 clang-format-16 clangd-16
&& apt-get -y install --no-install-recommends clang-tidy-17 clang-format-17 clangd-17

# libc++ for clang (not using libstdc++ from gcc)
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends lldb-16 lld-16 libc++-16-dev libc++abi-16-dev
&& apt-get -y install --no-install-recommends libc++-17-dev libc++abi-17-dev

# install gcc 13 (latest)

# =========== https://apt.llvm.org/ (Extras) ============
# LLVM
# RUN sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa -y
RUN sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends libllvm-16-ocaml-dev libllvm16 llvm-16 llvm-16-dev llvm-16-doc llvm-16-examples llvm-16-runtime
&& apt-get -y install --no-install-recommends g++-13 gcc-13

# clang
# FORCE UPGRADE
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends clang-16 clang-tools-16 clang-16-doc libclang-common-16-dev libclang-16-dev libclang1-16 clang-format-16 python3-clang-16 clangd-16 clang-tidy-16
&& apt-get -y upgrade

# ===========

# nodejs (for bazel)
RUN curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends nodejs
# install nvm (for npm)
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
RUN bash /root/.nvm/install.sh

# install npm (using nvm)
RUN bash -i -c "nvm install --lts"

# bazel
RUN npm install -g @bazel/bazelisk
# bazel (using npm)
RUN bash -i -c "npm install -g @bazel/bazelisk"

# install cpplint into /usr/local/bin/cpplint
RUN pip install cpplint
RUN python3 -m pip install cpplint

# bumpver (for versioning)
RUN python3 -m pip install bumpver

# default gcc-12
RUN sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 10
RUN sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 10
# default clang-16
RUN sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-16 10
RUN sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-16 10
RUN sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-16 10
RUN sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-16 10
RUN sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 10
RUN sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 10
# default clang-17
RUN sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 10
RUN sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 10
RUN sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-17 10
RUN sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-17 10
RUN sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-17 10

# ========== begin PANDOC part ===========

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install \
texlive texlive-base texlive-latex-extra texlive-latex-recommended \
texlive-bibtex-extra biber \
texlive-xetex texlive-fonts-extra \
texlive-science \
texlive-lang-portuguese

# install rust
RUN curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | bash -s -- -y

# pandoc 2.19.2
RUN wget https://github.com/jgm/pandoc/releases/download/2.19.2/pandoc-2.19.2-1-amd64.deb
RUN sudo dpkg -i pandoc-2.19.2-1-amd64.deb

# pandoc-crossref 0.3.13
RUN wget https://github.com/lierdakil/pandoc-crossref/releases/download/v0.3.13.0b/pandoc-crossref-Linux.tar.xz
RUN mv pandoc-crossref-Linux.tar.xz /usr/local/bin/
RUN (cd /usr/local/bin/ && tar xf pandoc-crossref-Linux.tar.xz)

# install pandoc-katex
RUN bash -c 'source ~/.cargo/env; cargo install pandoc-katex'

# install pandoc-latex-fontsize
RUN python3 -m pip install pandoc-latex-fontsize

32 changes: 22 additions & 10 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,42 @@
"build": {
"dockerfile": "Dockerfile"
},

"customizations": {
"vscode": {
"extensions": [
"mine.cpplint",
"DevonDCarew.bazel-code",
"llvm-vs-code-extensions.vscode-clangd",
"matepek.vscode-catch2-test-adapter",
]
"ms-vscode.cmake-tools",
"llvm-vs-code-extensions.vscode-clangd",
// "-ms-vscode.cpptools-extension-pack"
],
"settings": {
"C_Cpp.intelliSenseEngine": "disabled",
"clangd.arguments": [
"-log=verbose",
"-pretty",
"--background-index",
"--compile-commands-dir=${workspaceFolder}/build/",
],
"editor.formatOnSave": true,
"testMate.cpp.test.advancedExecutables": [
{
//"pattern": "{bazel-bin}/**/*{test}*"
"pattern": "{build}/**/*{test}*"
}
],
}
}
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "gcc -v",

// "postCreateCommand": "",
// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
}
50 changes: 37 additions & 13 deletions slides/1-revisao-tipos/1-revisao-tipos.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ fontsize: 10
header-includes:
- <link rel="stylesheet" type="text/css" href="general.css">
- <link rel="stylesheet" type="text/css" href="reveal-beamer.css">
pandoc-latex-fontsize:
- classes: [cpp, listing]
size: footnotesize
---


Expand Down Expand Up @@ -41,7 +44,7 @@ plataformas online: [onlinegdb.com/online_c++_compiler](https://www.onlinegdb.co
o aluno pode escolher o compilador de C ou da linguagem C++ (considerando padrão C++20).


# Tipos em C/C++
# Parte 1: Tipos Primitivos, Vetores, Agregados, Tipos Genéricos e Ponteiros em C/C++

------

Expand Down Expand Up @@ -74,15 +77,15 @@ float z = 3.7 ; // armazena o real 3.7 na variável z

**Pergunta/Resposta**: Cuidado com tipos. Quais são os valores armazenados nas variáveis abaixo (C++)?

```.cpp
```{.cpp .listing}
int x1 = 5; // => 5
int x2 = x1 + 8; // => 13
int x3 = x2 / 2; // => 6
float x4 = x2 / 2; // => 6.0
float x5 = x2 / 2.0; // => 6.5
auto x6 = 13; // => 13 (C warning: Wimplicit-int)
auto x7 = x2 / 2; // => ? (C warning: Wimplicit-int)
auto x8 = x2 / 2.0; // => ? (C warning: Wimplicit-int)
int x2 = x1 + 10; // => 15
int x3 = x2 / 2; // => 7
float x4 = x2 / 2; // => 7.0
float x5 = x2 / 2.0; // => 7.5
auto x6 = 15; // => 15 (C warning: Wimplicit-int)
auto x7 = x2 / 2; // => ? (C warning: Wimplicit-int)
auto x8 = x2 / 2.0; // => ? (C warning: Wimplicit-int)
```

Verifiquem essas operações de variáveis, escrevendo na saída padrão (tela do computador).
Expand All @@ -109,16 +112,14 @@ ao invés de indireta por atribuição (`operator=`).
------
## Impressão de Saída Padrão
Para imprimir na saída padrão utilizaremos o comando `print`.
Em C, tipicamente é utilizado o comando `printf`, mas devido a
inúmeras falhas de segurança, é recomendado o uso de uma alternativa mais segura.
O C++20 traz o header `<format>`, que é suficiente para implementar o `print`,
mas somente o C++23 traz o header `<print>` com método oficial `std::print`.
Então utilizaremos o comando `fmt::print`, da biblioteca `<fmt/core.h>`,
Somente o C++23 traz oficialmente o header `<print>` com método oficial `std::print`.
Então podemos utilizar o comando `fmt::print`, da biblioteca `<fmt/core.h>`,
ao invés do `std::print`, ainda indisponível no C++20.
```.cpp
Expand All @@ -135,6 +136,29 @@ int main() {

## Impressão de Saída Padrão

Tomando vantagem do padrão C++20 com o header `<format>`
é possível implementar uma versão simplificada do `print`
(sem depender de bibliotecas externas como `fmt::print`).
Uma possível solução utilizando macros de C é (tome cuidado
com possíveis efeitos indesejados de macros):

```.cpp
#include <format>

// Solution using __VA_ARGS__ and VA_OPT (## from c++20)
#define print(fmt, ...) \
printf("%s", std::format(fmt, ##__VA_ARGS__).c_str())

int main() {
print("olá mundo!\n");
return 0;
}
```

------

## Impressão de Saída Padrão

Para imprimir na saída padrão utilizaremos o comando `fmt::print`. Este
comando é dividido em duas partes, sendo que na primeira colocamos
a mensagem formatada e, a seguir, colocamos as variáveis cujo
Expand Down
Binary file modified slides/1-revisao-tipos/1-revisao-tipos.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions slides/1-revisao-tipos/header.tex
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

\usepackage[ruled,vlined,linesnumbered]{algorithm2e}



%\usepackage{listings}
%\renewenvironment{Shaded} {\begin{snugshade}\footnotesize} {\end{snugshade}}

%write file with 7 predefined 3D views
\usepackage{filecontents}
Expand Down
Loading

0 comments on commit 082e0ad

Please sign in to comment.