linux下enum類型占幾個字節,enum大小問題

問題描述

板卡有兩個CPU,ARM+MIPS,同時運行三個系統REE(linux) + TEE(SierraTEE) + SEE(TDS)。TEE跟SEE通過RPC進行通信,有enum成員的結構體信息傳遞會出錯,如下結構體:struct sTag {

enum A;

enum B;

int C;

enum D;

};

問題分析

這是由于SierraTEE和TDS使用的是不同的編譯器,而enum這種結構占用內存的大小只有在編譯的時候由編譯器決定的。顯然這是由于兩個編譯器對于enum的分配內存方式不一致導致的。

gcc編譯選項對此有相關說明:-fshort-enums

Allocate to an enum type only as many bytes as it needs for the declared range of possible

values. Specifically, the enum type will be equivalent to the smallest integer type which

has enough room.

Warning: the -fshort-enums switch causes GCC to generate code that is not binary compatible

with code generated without that switch. Use it to conform to a non-default application

binary interface.

即若指定了-fshort-enums,編譯器會分配滿足需求的內存給enum即可,以節省內存;如:若打開了-fshort-enums,sizeof(struct sTag) = 12;

若不打開-fshort-enums,sizeof(struct sTag) = 16;

問題解決

從根本上,尤其是在不同CPU上要使用相同變量作為參數,更應該避免使用enum,因為其size是不能被確定的。但由于TDS中相關的頭文件定義和API定義早以確定并廣泛使用了,這無法修改。

只要確認兩個編譯器使用相同的分配策略處理enum結構,我們選擇-fno-short-enums,即要求編譯器不要采取節省內存的方式,把沒一個enum變量都分配為int的大小。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541721.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541721.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541721.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ASP.NET導出word實例

ASP.NET導出word實例 最近遇到一個題目就是如何在asp.net中將數據導出到word中,由于數據是動態的,所以需要在后臺拼出想要的的格式,翻遍了網頁找出了一個比較滿意的代碼,感謝那位高手。代碼如下: public void Download…

Java LocalDate類| toString()方法與示例

LocalDate類toString()方法 (LocalDate Class toString() method) toString() method is available in java.time package. toString()方法在java.time包中可用。 toString() method is used to represent this LocalDate as a String by using the standards ISO-8601 format.…

linux14.04 Apache,Ubuntu 14.04編譯安裝Apache

Ubuntu下編譯安裝apache需要預先編譯安裝多個依賴件,包括:apr, apr-util,pcre,zlib-devel,等,相當麻煩,記錄于此備查.由于Ubuntu系統默認安裝時沒有安裝C,所以也需要先安裝c編譯需要相關的組件。[注]apt-ca…

Android Jenkins自動化構建之路

install Jenkins 添加Jenkins的源(repository): sudo wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/jenkins.repo sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key復制代碼yum install Jenkins復制代碼…

java 根據類名示例化類_Java即時類| plusMillis()方法與示例

java 根據類名示例化類即時類plusMillis()方法 (Instant Class plusMillis() method) plusMillis() method is available in java.time package. plusMillis()方法在java.time包中可用。 plusMillis() method is used to add the given duration in milliseconds to this Insta…

linux dd入門,Linux基礎知識:Linux中DD命令詳解

1.dd命令簡介功能:把指定的輸入文件拷貝到指定的輸出文件中,并且在拷貝過程中可以進行格式轉換。可以用該命令實現DOS下的diskcopy命令的作用。先用dd命令把軟盤上的數據寫成硬盤的一個寄存文件,再把這個寄存文件寫入第二張軟盤上&#xff0c…

CSS 字體(font)實例

1、設置文本字體 font-family:"Times New Roman",Georgia,Serif font-family:Arial,Verdana,Sans-serif 2、設置字體尺寸 font-size: 100% 3、設置字體風格 font-style:normal font-style:italic font-style:oblique 4、設置字體的異體 font-variant:normal text-var…

Java Duration類| 帶示例的compareTo()方法

持續時間類compareTo()方法 (Duration Class compareTo() method) compareTo() method is available in java.time package. compareTo()方法在java.time包中可用。 compareTo() method is used to compare this Duration object to the given object. compareTo()方法用于將此…

linux定時任務執行url,科技常識:linux定時任務訪問url實例

今天小編跟大家講解下有關linux定時任務訪問url實例 ,相信小伙伴們對這個話題應該也很關注吧,小編也收集到了有關linux定時任務訪問url實例 的相關資料,希望小伙伴會喜歡也能夠幫助大家。這次linux定時任務設置成功,也算是自己學習…

lcase和ucase_在SQL中使用UCASE(),LCASE()和MID()函數

lcase和ucaseUpper Case, Lower Case and MID functions are scalar functions which return a single value, based in the input value. 大寫,小寫和MID函數是標量函數,它們基于輸入值返回單個值。 As you all know sometimes different databases ha…

Maven的Settings.xml配置文件解釋

該配置用于單用戶配置和全局配置, 單用戶配置默認存放于 ${user.home}/.m2/目錄中. 全局配置默認存放于Maven安裝目錄下面的conf目錄中. 這兩個默認的位置都可以修改. <?xml version"1.0" encoding"UTF-8"?> <settings xmlns"http://m…

linux ntp手動授時,關于我校NTP授時服務的使用說明

校園網用戶&#xff1a;我中心于近期采購了GPS北斗授時服務設備&#xff0c;該設備可實現純GPS模式、純北斗模式和混合模式與衛星對時&#xff0c;同時實現對校內設備授時的功能。支持所有NTP協議的服務器、PC、嵌入式設備等&#xff0c;包括但不限于&#xff1a;Microsoft Win…

一串字符串轉換為ascii_將ASCII字符串(char [])轉換為C中的BYTE數組

一串字符串轉換為asciiGiven an ASCII string (char[]) and we have to convert it into BYTE array (BYTE[]) in C. 給定一個ASCII字符串(char [])&#xff0c;我們必須將其轉換為C語言中的BYTE數組(BYTE [])。 Logic: 邏輯&#xff1a; To convert an ASCII string to BYTE…

debugging Auto Layout:Logical Errors

Logical Errors邏輯錯誤 Logical errors are simply bugs. Somewhere, you have an assumption that is faulty. Perhaps it’s an assumption about how Auto Layout calculates the views’ frames. Perhaps it’s an assumption about the set of constraints that you’ve …

linux反序列化漏洞,思科多個產品Java反序列化漏洞(CVE-2015-6420)

思科多個產品Java反序列化漏洞(CVE-2015-6420)發布日期&#xff1a;2015-12-15更新日期&#xff1a;2015-12-17受影響系統&#xff1a;Cisco Unified ComputingCisco Voice and Unified Communications DevicesCisco Wireless描述&#xff1a;CVE(CAN) ID: CVE-2015-6420思科是…

密碼學替代技術_替代技術及其類型| 密碼學

密碼學替代技術As we already discussed what are the Substitution techniques and one of its type Ceasar Cipher? So we are not discussing it here for that please refer to Cryptography: CeasarCipher here: Cryptography: Caesar Cipher and its Python Implementat…

Flask+uwsgi+Nginx環境搭建

2019獨角獸企業重金招聘Python工程師標準>>> 開源軟件準備 需要的軟件列表&#xff1a; setuptools-33.1.1.zip Python-2.7.13.tgz pip-9.0.1.tar.gz nginx-1.10.3.tar.gz 軟件統一上傳到/usr/local/src/下&#xff0c;python是使用自己編譯的。Python安裝 先安裝以…

穿越迷宮c語言程序設計教程課后答案,實驗二 迷宮實驗.doc

#include #define ROW 11#define COLUMN 15typedef struct{ /*棧中的數據元素的類型定義*/int row; /*行下標*/int col; /*列下標*/int direction; /*下一步移動方向*/} DATA;Typedif struct node{ /* 棧類定義*/DATA data;Struct node *next;}LinkStack;Typedef struct{/*移動…

ofb模式_密碼學中的輸出反饋模式(OFB)

ofb模式This is an output feedback (OFB) mode is similar in structure to that of CFB in Cryptography. It is the output of the encryption function that is fed back to the shift register in OFB in the cryptography, whereas in CFB in the mode of blocks, the ci…

JavaScript0-閉包

1.閉包的概念&#xff1a;在JavaScript中局部作用域總是能夠訪問到全局作用域&#xff0c;即內部函數總是能夠訪問到外部函數的參數和變量&#xff0c;即使內部函數調用完畢。也就是指有權訪問到函數作用域里的變量。 function fn1() {var x 0;return function() {cosole.log(…