826是什么意思| 什么菜降血压| 口臭要做什么检查| 鲁迅为什么弃医从文| 不饱和脂肪酸是什么意思| 结婚40年是什么婚| com代表什么意思| 肠道肿瘤有什么症状| 子宫内膜粘连有什么症状| 肺胀是什么病| 舛是什么意思| 戒烟有什么方法| rococo是什么牌子| 肠胃痉挛什么症状| 右手掌心有痣代表什么| 化疗后吃什么食物最好| 徒手是什么意思| 4月9日什么星座| 隔空打牛是什么意思| 血糖高的人能吃什么水果| 痛风吃什么水果最好| 龟头发炎用什么药| 周公解梦梦见蛇是什么意思| 什么是清关| 湿疹是什么原因引起的起的| 儿童铅超标有什么症状| 上海玉佛寺求什么最灵验| 朱砂痣什么意思| 肝血虚吃什么中成药| 什么是硬下疳| 光年是什么单位| 口干口苦口臭是什么原因| 戾是什么意思| 中国国酒是什么酒| 女性白带有血丝是什么原因| shia是什么意思| 肛周脓肿是什么原因引起的| 什么车最长脑筋急转弯| 嘴角烂了涂什么药| 纳闷是什么意思| 荤菜是什么意思| 商纣王姓什么| 消化不良吃什么水果| 岁贡生是什么意思| 考试前紧张吃什么药最好能缓解| 兜底是什么意思| 梦见西红柿什么意思| 什么是卒中| 什么是虫草| 人走茶凉下一句是什么| 木石是什么字| 偶发房性早搏是什么意思| 同型半胱氨酸是什么| 加湿器有什么用| 梦见吃酒席是什么意思| 胆囊小是什么原因| 胎儿左心室灶状强回声是什么意思| dx是什么意思| 什么原因造成高血压| 天蝎座什么象星座| 救人一命胜造七级浮屠是什么意思| 吸毒是什么感觉| 方脸适合什么耳环| 什么是金融行业| 实至名归是什么意思| 喉咙发炎用什么药| 办健康证需要带什么| 因特网是什么意思| 细菌性痢疾吃什么药| 苟且是什么意思| 什么心什么意| 什么鲜花填动词| 子宫后位是什么意思| 放荡不羁爱自由什么意思| 感冒了可以吃什么水果| 胰腺炎吃什么药| 屈光检查是什么| 人老是放屁是什么原因| 对蚊子过敏是什么症状| 红细胞压积什么意思| 什么是腹式呼吸| 怀孕为什么会引起甲亢| 食管反流吃什么药| 过敏性紫癜看什么科| 什么是保健品| 211985是什么意思| 521是什么星座的| 水指什么生肖| 什么地站着| 什么油适合油炸| 新生儿什么时候可以喝水| 过门是什么意思| 做梦梦见狗咬我什么意思啊| 口腔脱皮是什么原因引起的| 邓字五行属什么| 什么是太监| 冬天喝什么茶好呢| 女人的胸长什么样| 五月十九日是什么星座| 挚友什么意思| 抑郁到什么程度要吃氟西汀| 我流是什么意思| px是什么单位| 94什么意思| 50是什么意思| 杜甫是什么朝代的| 皮肤痒用什么药| 为什么老是想睡觉| 阴帝是什么| 蜘蛛为什么不是昆虫| 鱼露是什么东西| 尿微量白蛋白高是什么原因| 心肌酶高有什么危害| 98年的虎是什么命| 什么是房补| 全会是什么意思| 拉肚子呕吐吃什么药| 荸荠是什么| 女人烂桃花多说明什么| 人参适合什么人吃| 梧桐树的叶子像什么| aosc是什么病| 什么是黑科技| 类风湿有什么特效药| 贫血检查查什么项目| 什么叫情绪| 做免疫组化意味什么| 肺大泡有什么危害| 检验葡萄糖用什么试剂| 开光的手串有什么禁忌| 梅毒长什么样| 国资委主任是什么级别| 清洁度111是什么意思| 腋窝出汗是什么原因| 蜗牛是什么生肖| 比基尼是什么意思| 43岁属什么| 秋葵长什么样| 1月15号是什么星座| 异地结婚登记需要什么证件| 猫咖是什么| 泌尿科主要看什么病| 克汀病是什么病| 凝胶是什么东西| 什么时间喝酸奶最好| 蛇的五行属什么| 半夜是什么生肖| 产妇能吃什么水果| 男人硬不起来是什么原因| 频发室性早搏吃什么药| 三文鱼不能和什么一起吃| 秋高气爽是什么意思| 会阴是什么部位| 梦见对象出轨什么征兆| 情景剧是什么意思| 什么人吃天麻最好| 体癣用什么药膏好得快| 事不过三是什么意思| 去极化是什么意思| 痛风为什么要禁欲| 娘酒是什么酒| 珠五行属什么| 开什么店最赚钱| 吃什么药通气放屁最快| 前列腺增生用什么药好| 为什么井盖是圆的| 学分是什么意思| 夏天适合用什么护肤品| 发膜是什么| 经常拉稀是什么原因| 膝盖后面叫什么部位| 胸闷气短吃什么药| 什么地方| 这什么意思| 肺纤维增殖灶是什么意思| 奶咖色是什么颜色| 无法入睡是什么原因| 男人为什么会晨勃| 误人子弟什么意思| 抽筋什么原因| 乳清粉是什么| 屁多是什么病的前兆| 不但而且是什么关系| 胎儿双侧肾盂无分离是什么意思| 蜻蜓是什么动物| 内热是什么原因引起的| 软肋骨炎吃什么药对症| 喝红茶对身体有什么好处| 玉皇大帝的老婆叫什么| 野生铁皮石斛什么价| 皮肤病用什么药膏好| 汾酒是什么香型| 什么是大健康产业| 丙申五行属什么| 骨科是什么意思| 人生最大的遗憾是什么| 云的五行属性是什么| 竖中指是什么意思| 为什么做梦会说梦话| 乌龟爱吃什么| 一个山一个空念什么| 中年人吃什么钙片补钙效果好| 什么是生育津贴| 梦见吃杨梅是什么意思| 乙肝表面抗体定量偏高什么意思| 小便泡沫多是什么原因| 湖南什么山最出名| 三国时期是什么朝代| 三高人群适合吃什么水果| 连奕名为什么娶杨若兮| 脂肪肝喝什么茶| 猫的祖先是什么动物| 什么生肖名扬四海| 冠状动脉粥样硬化性心脏病吃什么药| 6.25是什么日子| 火钳刘明什么意思| 迎风流泪用什么眼药水| 羊肉炖什么补肾壮阳| 工勤人员是什么意思| 骰子是什么意思| 女人味是什么| 羔羊跪乳是什么意思| 一天老是放屁是什么原因| 脸颊长痘痘什么原因| 幽门螺杆菌吃什么药最好| 三文鱼长什么样| 尿结石有什么症状| 食用植物油是什么油| 宫颈常大是什么意思| pt是什么意思| 一百万存款算什么水平| 唐氏筛查和无创有什么区别| 牡丹是什么季节开的| 防空警报是什么| 济南有什么特产| 孕妇梦见牛是什么意思| 碳酸盐质玉是什么玉| 吃辣流鼻涕是什么原因| 3个火读什么| 心悸心慌焦虑吃什么药能缓解| 金字旁的字和什么有关| 清明是什么季节| 和女生聊天聊什么| 咏柳中的咏是什么意思| 沈阳六院主要治什么病| 阳上人是什么意思| 驻马店古代叫什么| 吃什么补气虚最快最好| 什么是跨性别者| 肠痉挛是什么症状| 什么叫胰岛素抵抗| 母鸡学公鸡叫什么征兆| 低密度脂蛋白偏低是什么意思| 球蛋白偏低是什么原因| 驾驶证照片是什么底色| 容易出汗什么原因| 孢子是什么东西| 胆囊病变是什么意思| 京酱肉丝用什么酱| 手指甲没有月牙是什么原因| 两点水的字和什么有关| 为什么狗不能吃巧克力| 褪黑素是什么| 什么叫统招生| 百度

属虎和什么属相最配

百度 ABCDEFGHJKLMNQSTWXYZABCDFGHJLMNPQSTWXYZACDFGHJLMNPQSTWXYZABCDFGHJKLNPQRSTWXYZABCDFGHJKLMNPQRSTWXYZABCDFGHJKLMNPQRSTWXYZABCDEFGHJKLMNPQSTWYZABCDEFGHJKLMNPQRSTWXYZBCDEFGHJKLMNPQRSTWXYZABCDEFGHJKLMNPQRSTWXYZBDHJNTWXABCDEFGHJKLMNPQRSTWXYZABCDFGHJLMNPQSTWXYABCDFGHJKLMNPQRSTWXYZABCDFGHJKLMNPQRSTWXYZDGHJLPQSTWXYZABCDEFGHJKLMNPQRSTWXYZBCDGHJLMNPQTWXYZABCDFGHJKLMNPQRSTWXYZABCDFGHJKLNOPQRSTWXYZABCDEFGHJLMNQSTWXYZBCFHJMPQSXYBCDFHJKLNPQRSTWXYZABCDGJKLMNPQRSXYZABCDGHJKLMNPQSTWXYZBCDFGHJKLNPQRSTWXYZACDFGHJLNPQRSTWXYZABCDFGHJKLMNPQSTWXYZ

A foreign function interface (FFI) is a mechanism by which a program written in one programming language can call routines or make use of services written or compiled in another one. An FFI is often used in contexts where calls are made into a binary dynamic-link library.

Naming

edit

The term comes from the specification for Common Lisp, which explicitly refers to the programming language feature enabling for inter-language calls as such;[citation needed] the term is also often used officially by the interpreter and compiler documentation for Haskell,[1] Rust,[2] PHP,[3] Python, and LuaJIT (Lua)[4][5]:?35?.[6] Other languages use other terminology: Ada has language bindings, while Java has Java Native Interface (JNI), Java Native Access (JNA), or since Java 22, Foreign Function and Memory API. Foreign function interface has become generic terminology for mechanisms which provide such services.

Operation

edit

The primary function of a foreign function interface is to mate the semantics and calling conventions of one programming language (the host language, or the language which defines the FFI), with the semantics and conventions of another (the guest language). This process must also take into consideration the runtime environments and application binary interfaces of both. This can be done in several ways:

  • Requiring that guest-language functions which are to be host-language callable be specified or implemented in a particular way, often using a compatibility library of some sort.
  • Use of a tool to automatically wrap guest-language functions with appropriate glue code, which performs any necessary translation.
  • Use of a wrapper library
  • Restricting the set of host language abilities which can be used cross-language. For example, C++ functions called from C may not (in general) include reference parameters or throw exceptions.

FFIs may be complicated by the following considerations:

  • If one language supports garbage collection (GC) and the other does not; care must be taken that the non-GC language code does nothing to cause GC in the other to fail. In JNI, for example, C code which "holds on to" object references that it receives from Java must communicate this information successfully to the Java virtual machine or Java Runtime Environment (JRE), otherwise, Java may delete objects before C finishes with them. (The C code must also explicitly release its link to any such object once C has no further need of that object.)
  • Complicated or non-trivial objects or datatypes may be difficult to map from one environment to another.
  • It may not be possible for both languages to maintain references to the same instance of a mutable object, due to the mapping issue above.
  • One or both languages may be running on a virtual machine (VM); moreover, if both are, these are often different VMs.
  • Cross-language inheritance and other differences, such as between type systems or between object composition models, may be especially difficult.

 

Examples of FFIs include:

  • Ada language bindings, allowing not only to call foreign functions but also to export its functions and methods to be called from non-Ada code.[7]
  • C++ has a trivial FFI with C, as the languages share a significant common subset. The primary effect of the extern "C" declaration in C++ is to disable C++ name mangling. With other languages, separate utils or middleware are used, examples include:
  • Clean provides a bidirectional FFI with all languages following C or the stdcall calling convention.[8][9]
  • Common Lisp
  • Compiled Native Interface (CNI), alternative to JNI used in the GNU compiler environment.
  • One of the bases of the Component Object Model is a common interface format, which natively uses the same types as Visual Basic for strings and arrays.
  • D does it the same way as C++ does, with extern "C" through extern (C++)
  • Dart includes dart:ffi[10] library to call native C code for mobile, command-line, and server applications
  • Dynamic programming languages, such as Python, Perl, Tcl, and Ruby, all provide easy access to native code written in C, C++, or any other language obeying C/C++ calling conventions.
  • Factor has FFIs for C, Fortran, Objective-C, and Windows COM; all of these enable importing and calling arbitrary shared libraries dynamically.
  • Fortran 2003 has a module ISO_C_BINDING which provides interoperable data types (both intrinsic types and POD structs), interoperable pointers, interoperable global data stores, and mechanisms for calling C from Fortran and for calling Fortran from C.[11] It has been improved in the Fortran 2018 standard.
  • Go can call C code directly via the "C" pseudo-package.[12]
  • Google Web Toolkit (GWT), in which Java is compiled to JavaScript, has an FFI named JSNI which allows Java source code to call arbitrary JavaScript functions, and for JavaScript to call back into Java.
  • Haskell
  • Java Native Interface (JNI), which provides an interface between Java and C/C++, the preferred systems languages on most systems where Java is deployed. Java Native Access (JNA) provides an interface with native libraries without having to write glue code. In Java 22, the Foreign Function and Memory API was added which is a modern replacement for JNI.
  • LuaJIT, a just-in-time implementation of Lua, has an FFI that allows "calling external C functions and using C data structures from pure Lua code".[4][5]:?35?
  • .NET have FFI through its LibraryImport attribute.
  • Nim has an FFI which enables it to use source from C, C++, and Objective-C. It can also interface with JavaScript.
  • JavaScript usually runs inside web browser runtimes that don't provide direct access to system libraries or commands to run, but there are few exceptions:
    • Node.js provides functions to open precompiled .node modules that in turn may provide access to non-builtin resources.
    • Deno, provides kind of FFI interface via dlopen(...) functions.[13]
    • Bun provides a built-in module, bun:ffi, to efficiently call native libraries directly from JavaScript.[14]
  • Julia has ccall keyword to call C (and other languages, e.g., Fortran);[15] while packages, providing similar no-boilerplate support, are available for some languages e.g., for Python[16] (to e.g. provide OO support and GC support), Java (and supports other JDK-languages, such as Scala) and R. Interactive use with C++ is also possible with Cxx.jl package.
  • PhoneGap (was named Apache Callback, but is now Apache Cordova) is a platform for building native mobile applications using HTML, CSS and JavaScript. Also, it has FFIs via JavaScript callback functions for access to methods and properties of mobile phone's native features including accelerometer, camera (also PhotoLibrary and SavedPhotoAlbum), compass, storage (SQL database and localStorage), notification, media and capture (playing and recording or audio and video), file, contacts (address book), events, device, and connection information.[1],[2].
  • PHP provides FFI to C.[17]
  • Pony supports integration with C via its FFI.[18]
  • Python provides the ctypes and cffi modules. For example, the ctypes module can load C functions from a shared library, or dynamic-link library (DLL) on-the-fly and translate simple data types automatically between Python and C semantics as follows:
    import ctypes
    libc = ctypes.CDLL("/lib/libc.so.6")  # Under Linux/Unix
    t = libc.time(None)                   # Equivalent C code: t = time(NULL)
    print(t)
    
  • P/Invoke, which provides an interface between the Microsoft Common Language Runtime and native code.
  • Racket has a native FFI based heavily on macros that enables importing arbitrary shared libraries dynamically.[19][20]
  • Raku can call Ruby, Python, Perl, Brainfuck, Lua, C, C++, Go, Scheme (Guile, Gambit), and Rust[21][22]
  • Ruby provides FFI either through the ffi gem, or through the standard library fiddle.
    require 'fiddle'
    
    libm = Fiddle.dlopen('/lib/libm.so.6')
    
    # Equivalent to: double floor(double x);
    floor = Fiddle::Function.new(
      libm.sym('floor'),     # ptr is a referenced function(, or symbol), of a Fiddle::Handle.
      [Fiddle::TYPE_DOUBLE], # args is an Array of arguments, passed to the ptr function.
      Fiddle::TYPE_DOUBLE    # ret_type is the return type of the function
    )
    
    # Equivalent to: floor(3.14159);
    floor.call(3.14159) #=> 3.0
    
  • Rust defines a foreign function interface to functions with various standard application binary interface (ABIs) in namespace std::ffi for calling C code.[23] There is also a library called CXX for interfacing with C++, as well as for Elixir, Rustler.
  • V (Vlang) can include and supports the use of C source code and libraries.[24]
  • Visual Basic has a declarative syntax that allows it to call non-Unicode C functions.
  • Wolfram Language provides a technology named Wolfram Symbolic Transfer Protocol (WSTP) which enables bidirectional calling of code between other languages with bindings for C++, Java, .NET. and other languages.
  • Zig provides FFI to C using the builtin cImport function.[25]

In addition, many FFIs can be generated automatically: for example, SWIG. However, in the case of an extension language a semantic inversion of the relationship of guest and host can occur, when a smaller body of extension language is the guest invoking services in the larger body of host language, such as writing a small plugin[26] for GIMP.[27]

Some FFIs are restricted to free standing functions, while others also allow calls of functions embedded in an object or class (often called method calls); some even permit migration of complex datatypes or objects across the language boundary.

In most cases, an FFI is defined by a higher-level language, so that it may employ services defined and implemented in a lower-level language, typically a system programming language like C or C++. This is typically done to either access operating system (OS) services in the language in which the OS API is defined, or for performance goals.

Many FFIs also provide the means for the called language to invoke services in the host language also.

The term foreign function interface is generally not used to describe multi-lingual runtimes such as the Microsoft Common Language Runtime, where a common substrate is provided which enables any CLR-compliant language to use services defined in any other. (However, in this case the CLR does include an FFI, P/Invoke, to call outside the runtime.) In addition, many distributed computing architectures such as the Java remote method invocation (RMI), RPC, CORBA, SOAP and D-Bus permit different services to be written in different languages; such architectures are generally not considered FFIs.

Special cases

edit

There are some special cases, in which the languages compile into the same bytecode VM, like Clojure and Java, as well as Elixir and Erlang. Since there is no interface, it is not an FFI, strictly speaking, while it offers the same functions to the user.

See also

edit

References

edit
  1. ^ "FFI Introduction". HaskellWiki. Retrieved 19 June 2015. Haskell's FFI is used to call functions from other languages (basically C at this point), and for C to call Haskell functions.
  2. ^ "std::ffi". Rust-lang.org. Retrieved 1 April 2021. This module provides utilities to handle data across non-Rust interfaces, like other programming languages and the underlying operating system. It is mainly of use for FFI (Foreign Function Interface) bindings and code that needs to exchange C-like strings with other languages.
  3. ^ "PHP FFI Manual". PHP Manual. Retrieved 31 August 2023. Defined C variables are made available as properties of the FFI instance.
  4. ^ a b Mike Pall. "FFI Library". Luajit.org. Retrieved 2025-08-07.
  5. ^ a b Heintz, Joachim; Hofmann, Alex; McCurdy, Iain (2013). Ways Ahead: Proceedings of the First International Csound Conference. Newcastle upon Tyne: Cambridge Scholars Publishing. ISBN 978-1-4438-5122-0. OCLC 855505215.
  6. ^ "CFFI documentation". Retrieved 19 June 2015. C Foreign Function Interface for Python. The goal is to provide a convenient and reliable way to call compiled C code from Python using interface declarations written in C.
  7. ^ "Interface to Other Languages". Adaic.org. Retrieved 2025-08-07.
  8. ^ "Foreign Export". Retrieved 2025-08-07.
  9. ^ "Calling C From Clean". Retrieved 2025-08-07.
  10. ^ "dart:ffi library". Retrieved 2025-08-07.
  11. ^ "'fortran-iso-c-binding' tag wiki". Stack Overflow.
  12. ^ "cgo". Go Programming Language. Retrieved 2025-08-07.
  13. ^ "Foreign Function Interface | Manual". Deno. Retrieved 2025-08-07.
  14. ^ "FFI API". Bun Docs.
  15. ^ "Calling C and Fortran Code". JuliaLang.org. Retrieved 2025-08-07.
  16. ^ PyCall.jl: Package to call Python functions from the Julia language, JuliaPy, 2025-08-07, retrieved 2025-08-07
  17. ^ "PHP: FFI - Manual". The PHP Group. Retrieved 13 June 2019.
  18. ^ "Pony C-FFI Overview". Retrieved 9 April 2025.
  19. ^ Eli Barzilay. "The Racket Foreign Interface". Docs.racket-lang.org. Retrieved 2025-08-07.
  20. ^ "TR600.pdf" (PDF). Archived from the original (PDF) on 2025-08-07. Retrieved 2025-08-07.
  21. ^ "Inline implementations". Retrieved 2025-08-07.
  22. ^ "Native Call". Retrieved 2025-08-07.
  23. ^ "Using extern Functions to Call External Code". Retrieved 2025-08-07.
  24. ^ "Including C code". Vlang. Retrieved 2025-08-07.
  25. ^ "Import from C Header File". Zig Software Foundation. Retrieved 2025-08-07.
  26. ^ "4. A sample script". Gimp.org. 2025-08-07. Retrieved 2025-08-07.
  27. ^ "Script-Fu and plug-ins for The GIMP". Gimp.org. Retrieved 2025-08-07.
edit


压疮是什么 右膝关节退行性变是什么意思 你问我爱你有多深是什么歌 大张伟的真名叫什么 肾虚是什么原因引起的
高中生物学什么 被孤立的一般是什么人 树根有什么作用 小孩打嗝是什么原因 总是饿是什么原因
三十而立四十不惑什么意思 黄昏是什么时候 吃什么补维生素b 疱疹有什么症状表现 排卵期有什么症状
舌头麻是什么原因 夫妻肺片是什么 羊绒和羊毛有什么区别 牡丹鹦鹉吃什么 食道好像有东西堵着是什么原因
高血压吃什么药效果好hcv9jop6ns9r.cn 肾炎吃什么食物好cl108k.com 秋天穿什么hcv9jop5ns9r.cn 三月十三是什么星座xianpinbao.com 梦见亲人是什么意思hcv8jop7ns1r.cn
什么的愿望hcv9jop6ns4r.cn 猪肉和什么菜搭配最好hcv8jop5ns8r.cn 什么是芡实hcv7jop6ns7r.cn 孕妇喝什么牛奶对胎儿好aiwuzhiyu.com 牙齿贴片是什么意思hcv7jop6ns1r.cn
灰什么丧什么hcv8jop5ns5r.cn 粉玫瑰花语是什么意思hcv9jop5ns9r.cn 滑囊炎吃什么药aiwuzhiyu.com 请多指教是什么意思hcv8jop4ns6r.cn 做梦死人了是什么征兆gysmod.com
返流性食管炎用什么药hcv9jop0ns7r.cn 白化病是什么遗传hcv7jop6ns5r.cn mexican是什么牌子fenrenren.com 三顾茅庐是什么意思96micro.com 受委屈是什么意思hcv7jop9ns6r.cn
百度