V2EX  ›  英汉词典

Implicit Cast

定义 Definition

隐式类型转换(隐式强制转换):在编程语言中,编译器或解释器在不需要程序员显式写出转换语句(如 (int)static_cast<>)的情况下,自动把一个值从一种类型转换为另一种类型的过程。常见于数值运算、赋值、函数参数传递等场景。(不同语言规则不同;在某些语境中也常称 implicit conversion。)

发音 Pronunciation (IPA)

/ɪmˈplɪsɪt kæst/

例句 Examples

An implicit cast happens when you assign an int to a double.
当你把一个 int 赋值给 double 时,会发生一次隐式类型转换。

Because the function expects a size_t, passing a negative int may trigger an implicit cast and produce a very large value, leading to a subtle bug.
因为函数期望的是 size_t,传入负的 int 可能触发隐式类型转换并变成一个很大的值,从而造成隐蔽的 bug。

词源 Etymology

implicit 来自拉丁语 implicitus(“包含在内的、未明说的”),与 implicate 同源;cast 在这里是“投射/转换”的比喻用法,源自古诺尔斯语 kasta(“投掷”)。合起来表示“不明说但自动发生的转换”。

相关词 Related Words

文学与经典出处 Literary Works

  • The C++ Programming Language(Bjarne Stroustrup)——讨论转换规则与(隐式)转换/强制转换相关机制。
  • *Effective C++*(Scott Meyers)——多处提醒隐式转换可能带来意外行为,并给出避免策略。
  • *Programming: Principles and Practice Using C++*(Bjarne Stroustrup)——在类型系统与表达式章节中涉及隐式转换的常见情形。
  • C# in Depth(Jon Skeet)——讲解 C# 的隐式/显式转换(implicit/explicit operators)与相关语义。
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   3036 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 18ms · UTC 09:45 · PVG 17:45 · LAX 01:45 · JFK 04:45
♥ Do have faith in what you're doing.