为什么是C平台相关的? [英] Why is C platform-dependent?

查看:84
本文介绍了为什么是C平台相关的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么C必须重新编译为每个架构?没有这一切结束的比特和字节和负载反正跳?不每种架构基本上是通过最基本的命令以同样的方式?


解决方案

  1. 不同的CPU有不同的指令架构(例如,86 VS ARM)。

    • 早期Mac上使用摩托罗拉68K架构;后来者使用的PowerPC;仍然后来者使用的x86。在这些过渡,开发人员不得不自己出货的可执行脂肪的二进制文件,其中将包含对象code代表两种架构。


  2. 当前的x86 CPU具有32位和64位模式。

    • 这就是为什么你有Windows,Ubuntu的,等的32位和64位版本。


  3. 不同的操作系统提供不同的系统调用,图书馆等

    • 不同的OS的版本的可以提供不同的系统调用,图书馆等也(尽管操作系统厂商这么做的目的是尽可能地向后兼容)。


  4. 即使在相同的操作系统,调用约定不保证是不同的编译器之间是相同的。

    • 即使在相同的操作系统,不同的可执行文件格式可能在使用中。例如,在许多Unix系统,a.out的使用是所使用的格式,但大多数最终转换到ELF。在过渡期内,图书馆有两种格​​式提供。


Why does C have to be recompiled for each architecture? Doesn't it all end up as bits and bytes and loads and jumps anyway? Doesn't each architecture essentially go through the most basic commands in the same way?

解决方案

  1. Different CPUs have different instruction architectures (e.g., x86 vs ARM).
    • Early Macs used the Motorola 68k architecture; later ones used PowerPC; and still later ones used x86. During each of these transitions, developers had to ship their executables as fat binaries, which would contain object code for both architectures.
  2. Current x86 CPUs have 32-bit and 64-bit modes.
    • This is why you have 32-bit and 64-bit versions of Windows, Ubuntu, etc.
  3. Different operating systems provide different system calls, libraries, etc.
    • Different OS versions can provide different system calls, libraries, etc. also (although OS vendors do aim to be backward compatible as much as possible).
  4. Even on the same operating system, the calling convention is not guaranteed to be the same between different compilers.
    • Even on the same OS, different executable file formats may be in use. For example, on many Unix systems, a.out used to be the format used, but most eventually switched to ELF. During the transition period, libraries had to be provided in both formats.

这篇关于为什么是C平台相关的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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