C語言之-創(chuàng)新互聯(lián)

1.aligned定義

__attribute__((aligned(n))):表示指定類型的變量的最小對(duì)齊(以字節(jié)為單位)。

十載的漳縣網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營(yíng)銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整漳縣建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。成都創(chuàng)新互聯(lián)公司從事“漳縣網(wǎng)站設(shè)計(jì)”,“漳縣網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

如果結(jié)構(gòu)中有成員的長(zhǎng)度大于n,則按照大成員的長(zhǎng)度來對(duì)齊。

或者以下寫法:

__alignof(16)

__attribute__((packed)):表示取消在編譯過程中的優(yōu)化對(duì)齊。

2.程序例子
typedef struct {
    uint16_t version;                   // version of the info structure
    uint16_t size;                      // total size of the structure including version and size
    uint32_t sample_rate;               // sample rate in Hz
    audio_channel_mask_t channel_mask;  // channel mask
    audio_format_t format;              // audio format
    audio_stream_type_t stream_type;    // stream type
    uint32_t bit_rate;                  // bit rate in bits per second
    int64_t duration_us;                // duration in microseconds, -1 if unknown
    bool has_video;                     // true if stream is tied to a video stream
    bool is_streaming;                  // true if streaming, false if local playback
    uint32_t bit_width;
    uint32_t offload_buffer_size;       // offload fragment size
    audio_usage_t usage;
    audio_encapsulation_mode_t encapsulation_mode;  // version 0.2:
    int32_t content_id;                 // version 0.2: content id from tuner hal (0 if none)
    int32_t sync_id;                    // version 0.2: sync id from tuner hal (0 if none)
} __attribute__((aligned(8))) audio_offload_info_t;

結(jié)構(gòu)體按audio_offload_info_t按最8字節(jié)對(duì)齊。

3.調(diào)試
#includeint main(){
    //1.int 
    typedef int more_aligned_int __attribute__((aligned(16)));
    printf( "aligned: %ld, %ld\n", alignof(int), alignof(more_aligned_int)); // 4, 16

    //2.struct 
    struct S3 {more_aligned_int f;};
    struct S4 {int f;};
    printf( "S3 size: %ld, S4 size: %ld\n", sizeof(struct S3), sizeof(struct S4)); // 16, 4


    //3.array
    int arr[2] __attribute__((aligned(16))) = {1, 2};
    printf( "arr size: %ld, arr aligned: %ld\n", sizeof(arr), alignof(arr)); // 8, 16


    //4.packed
    struct S6 {more_aligned_int f;} __attribute__((packed));
    printf( "S6 size: %ld\n", sizeof(struct S6)); // 4
 

    //5.double
    struct S7 {double f;} __attribute__((aligned(4)));
    printf( "S7 size: %ld, algined: %ld\n", sizeof(struct S7), alignof(struct S7)); // 8, 8

    struct S8 {double f;} __attribute__((__aligned__(32)));
    printf( "S8 size: %ld, algined: %ld\n", sizeof(struct S8), alignof(struct S8)); // 32, 32
 
    return 0;
}

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購,新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧

文章名稱:C語言之-創(chuàng)新互聯(lián)
鏈接分享:http://muchs.cn/article48/dsipep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、建站公司、外貿(mào)網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、標(biāo)簽優(yōu)化、網(wǎng)頁設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化