Preprocessor #pragma directives issue compiler-specific instructions. Common uses in C include #pragma once to prevent multi-header inclusion and #pragma pack(push, 1) to eliminate memory padding alignment in hardware binary structures.

#pragma Header & Struct Packing Code Example

hardware_frame.hc
#pragma once // Modern alternative to #ifndef HEADER_H include guards
 
#include <stdio.h>
#include <stdint.h>
 
// Disable struct padding alignment to match raw binary network frame
#pragma pack(push, 1)
struct NetworkFrameHeader {
    uint8_t  preamble;
    uint16_t packet_id;
    uint32_t payload_len;
};
#pragma pack(pop) // Restore default compiler alignment