gpt4 book ai didi

c - 什么是动态回调?

转载 作者:太空宇宙 更新时间:2023-11-03 23:28:51 24 4
gpt4 key购买 nike

<分区>

我正在关注 Learn C The Hard Way在线。

作者有一次谈到了函数的“动态回调”。

谁能解释一下它到底是什么,因为我没听懂?

编辑

对于上下文,这里是用艰难的方式学习 C 的摘录:

Practical Pointer Usage

There are primarily four useful things you can do with pointers in C code:

• Ask the OS for a chunk of memory and use a pointer to work with it. This includes strings and something you haven’t seen yet, structs.

• Pass large blocks of memory (like large structs) to functions with a pointer, so you don’t have to pass the whole thing to them.

• Take the address of a function so you can use it as a dynamic callback.

• Scan complex chunks of memory, converting bytes off of a network socket into data structures or parsing files.

For nearly everything else, you might see people use pointers when they should be using arrays. In the early days of C programming, people used pointers to speed up their programs, because the compilers were really bad at optimizing array usage. These days, the syntax to access an array versus a pointer are translated into the same machine code and optimized in the same way, so it’s not as necessary. Instead, you should go with arrays whenever you can, and then only use pointers as a performance optimization if you absolutely have to.

Excerpt From: Zed A. Shaw. “Learn C the Hard Way: Practical Exercises on the Computational Subjects You Keep Avoiding (Like C) (Brianne Kwasny's Library).”

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com