2025-03-10 08:23:02 -03:00
|
|
|
#+title: Curso Básico da Linguagem C
|
|
|
|
#+subtitle: Aula 1: História
|
|
|
|
#+author: Blau Araujo
|
|
|
|
#+startup: show2levels
|
|
|
|
#+options: toc:3
|
|
|
|
|
|
|
|
* Aula 1: História
|
|
|
|
|
|
|
|
[[https://youtu.be/wqJQL5W9FIw][Vídeo desta aula]]
|
|
|
|
|
|
|
|
** Principais momentos...
|
|
|
|
|
|
|
|
- Ken Thompson cria a linguagem B (1969) para ter uma linguagem de alto nível
|
|
|
|
para reescrever o UNIX.
|
|
|
|
|
|
|
|
- Dennis Ritchie continua aprimorando a linguagem B.
|
|
|
|
|
|
|
|
- Em 1972, a linguagem B está tão diferente que recebe o nome de linguagem C.
|
|
|
|
|
|
|
|
- Em 1978, Brian Kernighan e Dennis Ritchie lançam o livro: /The C Programming
|
|
|
|
Language/, que acaba se tornando a primeira especificação da linguagem.
|
|
|
|
|
|
|
|
- Entre 1983 e 1989, são escritas as primeiras especificações ANSI (ISO/IEC)
|
|
|
|
para a linguagem.
|
|
|
|
|
|
|
|
- Os racunhos de 1987 (C87) são utilizados para escrever a segunda edição do
|
|
|
|
livro, com o nome de /The ANSI C Programming Language/.
|
|
|
|
|
|
|
|
** Características da linguagem C...
|
|
|
|
|
|
|
|
- Linguagem compilada
|
|
|
|
- De alto nível
|
|
|
|
- De uso geral
|
|
|
|
- Imperativa
|
|
|
|
- Procedural
|
|
|
|
- Estruturada
|
|
|
|
|
|
|
|
** Implementação GNU/Linux...
|
|
|
|
|
|
|
|
*** Compilador:
|
|
|
|
|
|
|
|
- /GNU Compiler Collection/ (=gcc=)
|
|
|
|
|
|
|
|
*** Biblioteca C Padrão:
|
|
|
|
|
|
|
|
- GNU Libc (=glibc=)
|
|
|
|
|
2025-03-10 10:52:59 -03:00
|
|
|
*** Obter a especificação padrão do gcc...
|
|
|
|
|
|
|
|
#+begin_example
|
|
|
|
:~$ gcc -E -dM -x c /dev/null | grep '__STDC_VERSION__'
|
|
|
|
#define __STDC_VERSION__ 201710L
|
|
|
|
#+end_example
|
|
|
|
|
|
|
|
- =-E=: Para a compilação após gerar o código pré-processado.
|
|
|
|
- =-dM=: Filtra todas as diretivas que definem macros.
|
|
|
|
- =-x c=: Especifica a linguagem (no caso, =c=).
|
|
|
|
- =/dev/null=: Compilar o arquivo vazio =/dev/null=.
|
|
|
|
|
2025-03-10 08:23:02 -03:00
|
|
|
** Compilação...
|
|
|
|
|
|
|
|
Transformação do código-fonte em texto do programa para um código binário em
|
|
|
|
linguagem de máquina.
|
|
|
|
|
|
|
|
*** Etapas:
|
|
|
|
|
|
|
|
1 - Pré-processamento:
|
|
|
|
|
|
|
|
#+begin_example
|
|
|
|
gcc -E arquivo.c → Saída padrão
|
|
|
|
#+end_example
|
|
|
|
|
|
|
|
2 - Compilação:
|
|
|
|
|
|
|
|
#+begin_example
|
|
|
|
gcc -S arquivo.c → arquivo.s (fonte em assembly)
|
|
|
|
#+end_example
|
|
|
|
|
|
|
|
3 - Montagem:
|
|
|
|
|
|
|
|
#+begin_example
|
|
|
|
gcc -c arquivo.c → arquivo.o (objeto binário)
|
|
|
|
#+end_example
|
|
|
|
|
|
|
|
4 - Link-edição:
|
|
|
|
|
|
|
|
#+begin_example
|
|
|
|
gcc arquivo.c → a.out (arquivo binário executável)
|
|
|
|
#+end_example
|
|
|
|
|
|
|
|
** Exemplo de um programa em C...
|
|
|
|
|
|
|
|
Programa =salve.c=:
|
|
|
|
|
|
|
|
#+begin_src c
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
|
|
|
|
puts("Salve, simpatia!");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
*** Compilação:
|
|
|
|
|
|
|
|
#+begin_example
|
|
|
|
:~/git/cblc/aulas/01-historia$ gcc -o salve salve.c
|
|
|
|
#+end_example
|
|
|
|
|
|
|
|
*** Execução:
|
|
|
|
|
|
|
|
#+begin_example
|
|
|
|
:~/git/cblc/aulas/01-historia$ ./salve
|
|
|
|
Salve, simpatia!
|
|
|
|
#+end_example
|
|
|
|
|