日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

    歡迎訪問 生活随笔!

    生活随笔

    當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

    编程问答

    Pragma是什么?

    發布時間:2025/3/15 编程问答 23 豆豆
    生活随笔 收集整理的這篇文章主要介紹了 Pragma是什么? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
    Pragma是什么? Pragma是什么?
    翻譯:SkyJacker
    后附英文原文。


    (譯者注:
    一句話,pragma就是為了讓編譯器編譯出的C或C++程序與機器硬件和操作系統保持完全兼容而定義的宏擴展,
    #pragma是和特定編譯器相關的。)
    兩部分:
    1.Pragma說明;
    2.Pragma的語法。

    一、Pragma說明(Directives)

    C和C++程序的每次執行都支持其所在的主機或操作系統所具有的一些獨特的特點。
    一些程序,例如,需要精確控制數據存放的內存區域或控制某個函數接收的參數。
    #pragma指示為編譯器提供了一種在不同機器和操作系統上編譯以保持C和C++完全兼容的方法。?
    Pragmas是由機器和相關的操作系統定義的,通常對每個編譯器來說是不同的。


    二、語法(Syntax)

    #pragma token-string(特征字符串)

    特征字符串是一連串的字符,就是要給一個特定編譯器提供說明和編譯意見。

    符號(#)必須是pragma所在那一行的第一個非空格字符;
    #號和pragma之間可以有任意個空格符。
    在#pragma之后,是可以被編譯器解析的預處理特征字符。
    一般認為,#pragma屬于宏擴展。
    如果編譯器發現不認識的pragma,會提出警告,但繼續編譯下去。

    Pragmas可以用在條件聲明上,提供最新的功能性的預處理程序,或者提供給編譯器定義執行的信息。
    C和C++編譯器認可如下pragmas:
    alloc_text
    comment //注釋
    init_seg1?
    optimize? //最優化
    auto_inline
    component? //組成部件
    inline_depth
    pack?????? //包
    bss_seg
    data_seg
    inline_recursion? //內嵌遞歸
    pointers_to_members1
    check_stack
    function???
    intrinsic? //內在的
    setlocale
    code_seg
    hdrstop
    message?
    vtordisp1
    const_seg
    include_alias
    once
    warning


    這是MSDN的一篇文章,原作者曾經想使用
    #pragma pack(1) // 用GCC在MIPS平臺上將結構體成員結合到一塊連續的內存塊,但是沒有做到。

    在linux環境下使用intel-based GCC,#pragma pack(1)可以工作。

    建議參考具體編譯器的文檔,在里面應該有pragma的說明。

    ---------------------------------------原文-------------------------------------------

    Pragma Directives
    Each implementation of C and C++ supports some features unique to its host machine or operating system.

    Some programs, for instance, need to exercise precise control over the memory areas where data is placed or

    to control the way certain functions receive parameters.
    The #pragma directives offer a way for each compiler
    to offer machine- and operating-system-specific features
    while retaining overall compatibility with the C and C++
    languages. Pragmas are machine- or operating-system-specific by definition,
    and are usually different for every compiler.

    Syntax

    #pragma token-string

    The token-string is a series of characters that gives a specific compiler instruction and arguments,
    if any.

    The number sign (#) must be the first non-white-space character on the line containing the pragma;

    white-space characters can separate the number sign and the word pragma.
    Following #pragma, write any text that the translator can parse as preprocessing tokens.
    The argument to #pragma is subject to macro expansion.

    If the compiler finds a pragma it does not recognize, it issues a warning, but compilation continues.

    Pragmas can be used in conditional statements, to provide new preprocessor functionality,
    or to provide implementation-defined information to the compiler.
    The C and C++ compilers recognize the following pragmas:

    alloc_text comment init_seg1 optimize
    auto_inline component inline_depth pack
    bss_seg data_seg inline_recursion pointers_to_members1
    check_stack function intrinsic setlocale
    code_seg hdrstop message vtordisp1
    const_seg include_alias once warning


    This is an article from MSDN, I ever wanted to use
    #pragma pack(1) //which can combine structure members to one continuous memory block
    on MIPS platform using GCC, but it doesn't work.


    See the compiler's document, it should be illustrated there.

    Under linux env using intel-based GCC, it works.

    總結

    以上是生活随笔為你收集整理的Pragma是什么?的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。