> For the complete documentation index, see [llms.txt](https://mentebinaria.gitbook.io/manual-da-linguagem-gnu-c/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mentebinaria.gitbook.io/manual-da-linguagem-gnu-c/10.-ordem-de-execucao/associatividade-e-ordenacao.md).

# Associatividade e Ordenação

Um operador binário associativo, como `+`, quando usado repetidamente, pode combinar qualquer número de operandos. Os valores dos operandos podem ser calculados em qualquer ordem.

Se os valores forem inteiros e o estouro puder ser ignorado, eles podem ser combinados em qualquer ordem. Assim, dadas quatro funções que retornam `unsigned int`, chamá-las e somar seus resultados, como no exemplo:

```c
(foo () + bar ()) + (baz () + quux ())
```

pode somar os resultados em qualquer ordem.

Por outro lado, a aritmética com inteiros com sinal, em que o estouro é significativo, nem sempre é associativa (veja [Estouro de Inteiros](/manual-da-linguagem-gnu-c/6.-aritmetica/estouro-de-inteiros.md)). Portanto, as somas devem ser realizadas na ordem especificada, obedecendo os parênteses e a associação à esquerda. Isso significa calcular `(foo () + bar ())` e `(baz () + quux ())` primeiro (em qualquer ordem), depois somar os dois.

O mesmo se aplica à aritmética com valores de ponto flutuante, já que ela também não é realmente associativa. No entanto, a opção do GCC `-funsafe-math-optimizations` permite que o compilador altere a ordem de cálculo quando uma operação associativa (associativa na matemática exata) combina vários operandos. Essa opção entra em vigor ao compilar um módulo (veja Compilação[^1]). Alterar a ordem de associação pode permitir que o programa otimize a execução das operações de ponto flutuante.

Em todos esses casos, as quatro chamadas de função podem ser realizadas em qualquer ordem. Não há certo ou errado nisso.

[^1]: **Capítulo pendente de tradução**


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://mentebinaria.gitbook.io/manual-da-linguagem-gnu-c/10.-ordem-de-execucao/associatividade-e-ordenacao.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
