C 中整数或任何其他数据类型的大小是否取决于底层架构? [英] Does the size of the integer or any other data types in C dependent on the underlying architecture?

查看:26
本文介绍了C 中整数或任何其他数据类型的大小是否取决于底层架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>

int main()
{
  int c; 
  return 0;
} // on Intel architecture

#include <stdio.h>

int main()
{
  int c; 
  return 0;
}// on AMD architecture

/*在这里,我在两台不同的机器上有一个代码,我想知道数据类型的大小是否取决于机器"*/

/* Here I have a code on the two different machines and I want to know the 'Is the size of the data types dependent on the machine ' */

推荐答案

请看这里:C 和 C++ 中整数/算术类型的大小保证

基本的 C 类型大小取决于实现(编译器)和架构,但是它们有一些有保证的边界.因此,永远不要对类型大小进行硬编码,而应使用 sizeof(TYPENAME) 来获取它们的长度(以字节为单位).

Fundamental C type sizes are depending on implementation (compiler) and architecture, however they have some guaranteed boundaries. One should therefore never hardcode type sizes and instead use sizeof(TYPENAME) to get their length in bytes.

这篇关于C 中整数或任何其他数据类型的大小是否取决于底层架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆