是否必须了解机器架构才能编写代码? [英] Would one have to know the machine architecture to write code?

查看:24
本文介绍了是否必须了解机器架构才能编写代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我正在使用 Java 或 Python 或 C++ 进行编程以解决一个简单的问题,可能是构建 TCP/UDP 回显服务器或阶乘计算.我是否需要担心架构细节,即它是 32 位还是 64 位?

Let's say I'm programming in Java or Python or C++ for a simple problem, could be to build an TCP/UDP echo server or computation of factorial. Do I've to bother about the architecture details, i.e., if it is 32 or 64-bit?

恕我直言,除非我正在编写一些与相当低级的东西有关的东西,否则我不必担心它是 32 位还是 64 位.我哪里错了?还是我说的对???

IMHO, unless I'm programming something to do with fairly low-level stuff then I don't have to bother if its 32 or 64 bit. Where am I going wrong? Or am I correct???

推荐答案

适用于大多数情况

运行时/语言/编译器将抽象这些细节,除非您在低级别直接处理字长或二进制.

The runtime/language/compiler will abstract those details unless you are dealing directly with word sizes or binary at a low level.

内核中的 NIC/网络堆栈甚至抽象出字节顺序.它为您翻译.使用 C 编写套接字时,有时必须在发送数据时处理网络的字节顺序……但这与 32 位或 64 位差异无关.

Even byteorder is abstracted by the NIC/Network stack in the kernel. It is translated for you. When programming sockets in C, you do sometimes have to deal with byte ordering for the network when sending data ... but that doesn't concern 32 or 64 bit differences.

在处理二进制数据的 blob 时,将它们从一种架构映射到另一种架构(例如作为 C 结构的覆盖)可能会导致其他人提到的问题,但这就是我们开发基于字符和架构的独立协议的原因以此类推.

When dealing with blobs of binary data, mapping them from one architecture to another (as an overlay to a C struct for example) can cause problems as others have mentioned, but this is why we develop architecture independent protocols based on characters and so on.

事实上,Java 之类的东西在虚拟机中运行,将机器抽象化又一步!

In-fact things like Java run in a virtual machine that abstracts the machine another step!

稍微了解架构的指令集,以及如何编译语法可以帮助您理解平台并编写更清晰、更紧凑的代码.我知道在学习了编译器后,我对一些旧的 C 代码做了个鬼脸!

Knowing a bit about the instruction set of the architecture, and how the syntax is compiled to that can help you understand the platform and write cleaner, tighter code. I know I grimace at some old C code after studying compilers!

这篇关于是否必须了解机器架构才能编写代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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