Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Other | Compiler Directives and Advanced Control
C Preprocessing
course content

Conteúdo do Curso

C Preprocessing

C Preprocessing

1. Introduction to Preprocessing
2. Macros
3. Conditional compilation
4. Compiler Directives and Advanced Control

book
Other

In addition to #pragma once, #pragma pack, and #pragma GCC diagnostic, there are several other important #pragma directives used to control compilation in various scenarios.

Memory Layout and Alignment

c

main

copy
123456789101112131415
#include <stdio.h> // Align structure members with 1-byte boundaries #pragma pack(push, 1) typedef struct { char a; // 1 byte int b; // 4 bytes } PackedStruct; #pragma pack(pop) int main() { // Print size of the structure with no padding printf("Size of PackedStruct: %zu\n", sizeof(PackedStruct)); return 0; }

Diagnostics and Warnings

c

main

copy
1234567891011121314151617
#include <stdio.h> // Suppress warning about unused static functions #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" // Normally triggers a warning, but it is now ignored static void unused_helper() { printf("This helper is never called.\n"); } #pragma GCC diagnostic pop int main() { printf("No warnings about unused functions.\n"); return 0; }

Performance and Optimization

c

main

copy
123456789101112131415
#include <stdio.h> // Example function to call in a loop void process(int i) { printf("Processing %d\n", i); } int main() { // Suggest loop unrolling to the compiler #pragma unroll 4 for (int i = 0; i < 8; i++) { process(i); } return 0; }
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 4

Pergunte à IA

expand
ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

course content

Conteúdo do Curso

C Preprocessing

C Preprocessing

1. Introduction to Preprocessing
2. Macros
3. Conditional compilation
4. Compiler Directives and Advanced Control

book
Other

In addition to #pragma once, #pragma pack, and #pragma GCC diagnostic, there are several other important #pragma directives used to control compilation in various scenarios.

Memory Layout and Alignment

c

main

copy
123456789101112131415
#include <stdio.h> // Align structure members with 1-byte boundaries #pragma pack(push, 1) typedef struct { char a; // 1 byte int b; // 4 bytes } PackedStruct; #pragma pack(pop) int main() { // Print size of the structure with no padding printf("Size of PackedStruct: %zu\n", sizeof(PackedStruct)); return 0; }

Diagnostics and Warnings

c

main

copy
1234567891011121314151617
#include <stdio.h> // Suppress warning about unused static functions #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" // Normally triggers a warning, but it is now ignored static void unused_helper() { printf("This helper is never called.\n"); } #pragma GCC diagnostic pop int main() { printf("No warnings about unused functions.\n"); return 0; }

Performance and Optimization

c

main

copy
123456789101112131415
#include <stdio.h> // Example function to call in a loop void process(int i) { printf("Processing %d\n", i); } int main() { // Suggest loop unrolling to the compiler #pragma unroll 4 for (int i = 0; i < 8; i++) { process(i); } return 0; }
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 4
Sentimos muito que algo saiu errado. O que aconteceu?
some-alt