C语言之-创新互联
1.aligned定义
文章名称:C语言之-创新互联
URL标题:http://pwwzsj.com/article/dsipep.html
__attribute__((aligned(n))):表示指定类型的变量的最小对齐(以字节为单位)。
十载的漳县网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整漳县建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联公司从事“漳县网站设计”,“漳县网站推广”以来,每个客户项目都认真落实执行。如果结构中有成员的长度大于n,则按照大成员的长度来对齐。
或者以下写法:
__alignof(16)
__attribute__((packed)):表示取消在编译过程中的优化对齐。
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;
结构体按audio_offload_info_t按最8字节对齐。
3.调试#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;
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
文章名称:C语言之-创新互联
URL标题:http://pwwzsj.com/article/dsipep.html