C 语言函数指针 (Pointers to Functions, Function Pointers)
C 语言函数指针 {Pointers to Functions, Function Pointers}
- 1. Pointers to Functions (函数指针)
- 2. Function Pointers (函数指针)
- 2.1. Declaring Function Pointers
- 2.2. Assigning Function Pointers
- 2.3. Calling Function Pointers
- 3. Jump Tables (转移表)
- References
1. Pointers to Functions (函数指针)
jump tables and passing a function pointer as an argument in a function call
函数指针最常见的两个用途是转换表和作为参数传递给另一个函数。
Like any other pointer, a pointer to a function must be initialized to point to something before indirection can be performed on it.
和其他指针一样,对函数指针执行间接访问之前必须把它初始化为指向某个函数。
The following code fragment illustrates one way to initialize a pointer to a function.
int f(int);int(*pf)(int) = &f;
The second declaration creates pf
, a pointer to a function, and initializes it to point to the function f
. The initialization can also be accomplished with an assignment statement.
第 2 个声明创建了函数指针 pf
,并把它初始化为指向函数 f
。函数指针的初始化也可以通过一条赋值语句来完成。
It is important to have a prototype for f
prior to the initialization, for without it the compiler would be unable to check whether the type of f
agreed with that of pf
.
在函数指针的初始化之前具有 f
的原型是很重要的,否则编译器就无法检查 f
的类型是否与 pf
所指向的类型一致。
The ampersand in the initialization is optional, because the compiler always converts function names
to function pointers
wherever they are used. The ampersand does explicitly what the compiler would have done implicitly anyway.
初始化表达式中的 &
操作符是可选的,因为函数名被使用时总是由编译器把它转换为函数指针。&
操作符只是显式地说明了编译器将隐式执行的任务。
ampersand /ˈæmpəsænd/:n. &
After the pointer has been declared and initialized, there are three ways to call the function:
int ans;ans = f(25);ans = (*pf)(25);ans = pf(25);
The first statement simply calls the function f
by name, though its evaluation is probably not what you expected. The function name f
is first converted to a pointer to the function; the pointer specifies where the function is located. The function call operator then invokes the function by executing the code beginning at this address.
第 1 条语句简单地使用名字调用函数 f
,但它的执行过程可能和你想象的不太一样。函数名 f
首先被转换为一个函数指针,该指针指定函数在内存中的位置。然后,函数调用操作符调用该函数,执行开始于这个地址的代码。
The second statement applies indirection to pf
, which converts the function pointer to a function name. This conversion is not really necessary, because the compiler converts it back to a pointer before applying the function call operator. Nevertheless, this statement has exactly the same effect as the first one.
第 2 条语句对 pf
执行间接访问操作,它把函数指针转换为一个函数名。这个转换并不是真正需要的,因为编译器在执行函数调用操作符之前又会把它转换回去。不过,这条语句的效果和第 1 条语句是完全一样的。
The third statement has the same effect as the first two. Indirection is not needed, because the compiler wants a pointer to the function anyway. This example shows how function pointers are usually used.
第 3 条语句和前两条语句的效果是一样的。间接访问操作并非必需,因为编译器需要的是二个函数指针。这个例子显示了函数指针通常是如何使用的。
The two most common uses of pointers to functions are passing a function pointer as an argument in a function call and jump tables.
两个最常见的用途是把函数指针作为参数传递给函数以及用于转换表。
2. Function Pointers (函数指针)
A function name refers to a fixed function. Sometimes it is useful to call a function to be determined at run time; to do this, you can use a function pointer value
that points to the chosen function (see Pointers).
函数名指的是固定函数。
Pointer-to-function types can be used to declare variables and other data, including array elements, structure fields, and union alternatives. They can also be used for function arguments and return values. These types have the peculiarity that they are never converted automatically to void *
or vice versa. However, you can do that conversion with a cast.
指向函数的指针类型可用于声明变量和其他数据,包括数组元素、结构字段和联合替代项。它们还可用于函数参数和返回值。这些类型的特性是它们永远不会自动转换为 void *
。但是,你可以使用强制类型转换来完成这种转换。
2.1. Declaring Function Pointers
The declaration of a function pointer variable (or structure field) looks almost like a function declaration, except it has an additional *
just before the variable name. Proper nesting requires a pair of parentheses around the two of them. For instance, int (*a) ();
says, “Declare a
as a pointer such that *a
is an int
-returning function.”
正确的嵌套需要用一对括号括住它们两个。
Contrast these three declarations:
// Declare a function returning char *
char *a (char *);
// Declare a pointer to a function returning char
char (*a) (char *);
// Declare a pointer to a function returning char *
char *(*a) (char *);
The possible argument types of the function pointed to are the same as in a function declaration. You can write a prototype that specifies all the argument types:
rettype (*function) (arguments…);
or one that specifies some and leaves the rest unspecified:
rettype (*function) (arguments…, ...);
or one that says there are no arguments:
rettype (*function) (void);
You can also write a non-prototype declaration that says nothing about the argument types:
rettype (*function) ();
For example, here’s a declaration for a variable that should point to some arithmetic function that operates on two double
s:
double (*binary_op) (double, double);
Structure fields, union alternatives, and array elements can be function pointers; so can parameter variables. The function pointer declaration construct can also be combined with other operators allowed in declarations. For instance,
int **(*foo)();
declares foo
as a pointer to a function that returns type int **
, and
int **(*foo[30])();
declares foo
as an array of 30 pointers to functions that return type int **
.
int **(**foo)();
declares foo
as a pointer to a pointer to a function that returns type int **
.
2.2. Assigning Function Pointers
Assuming we have declared the variable binary_op
as in the previous section, giving it a value requires a suitable function to use. So let’s define a function suitable for the variable to point to. Here’s one:
double double_add(double a, double b) {return a + b;
}
Now we can give it a value:
binary_op = double_add;
The target type of the function pointer must be upward compatible with the type of the function.
There is no need for &
in front of double_add
. Using a function name such as double_add
as an expression automatically converts it to the function’s address, with the appropriate function pointer type. However, it is ok to use &
if you feel that is clearer:
binary_op = &double_add;
2.3. Calling Function Pointers
To call the function specified by a function pointer, just write the function pointer value in a function call. For instance, here’s a call to the function binary_op
points to:
binary_op (x, 5)
Since the data type of binary_op
explicitly specifies type double
for the arguments, the call converts x
and 5
to double
.
The call conceptually dereferences the pointer binary_op
to “get” the function it points to, and calls that function. If you wish, you can explicitly represent the dereference by writing the *
operator:
(*binary_op) (x, 5)
The *
reminds people reading the code that binary_op
is a function pointer rather than the name of a specific function.
*
提醒阅读代码的人 binary_op
是一个函数指针,而不是特定函数的名称。
3. Jump Tables (转移表)
The following code fragment is from a program that implements a pocket calculator. Other parts of the program have already read in two numbers (op1
and op2
) and an operator (oper
). This code tests the operator to determine which function to invoke.
下面的代码段取自一个程序,它用于实现一个袖珍式计算器。程序的其他部分已经读入两个数 (op1
and op2
) 和一个操作符 (oper
)。下面的代码对操作符进行测试,然后决定调用哪个函数。
switch (oper) {case ADD:result = add(op1, op2);break;case SUB:result = sub(op1, op2);break;case MUL:result = mul(op1, op2);break;case DIV:result = div(op1, op2);break;...}
It is good design to separate the operations from the code that chooses among them. The more complex operations will certainly be implemented as separate functions because of their size, but even the simple operations may have side effects, such as saving a constant value for later operations.
把具体操作和选择操作的代码分开是一种良好的设计方案。更为复杂的操作将肯定以独立的函数来实现,因为它们的长度可能很长。但即使是简单的操作也可能具有副作用,例如保存一个常量值用于以后的操作。
In order to use a switch
, the codes that represent the operators must be integers. If they are consecutive integers starting with zero, we can use a jump table to accomplish the same thing. A jump table is just an array of pointers to functions.
为了使用 switch
语句,表示操作符的代码必须是整数。如果它们是从零开始连续的整数,我们可以使用转换表来实现相同的任务。转换表就是一个函数指针数组。
There are two steps in creating a jump table. First, an array of pointers to functions is declared and initialized. The only trick is to make sure that the prototypes for the functions appear before the array declaration.
创建一个转换表需要两个步骤。首先,声明并初始化一个函数指针数组。唯一需要留心之处就是确保这些函数的原型出现在这个数组的声明之前。
double add(double, double);double sub(double, double);double mul(double, double);double div(double, double);...double (*oper_func[])(double, double) = {add, sub, mul, div, ...};
The proper order for the functionsʹ names in the initializer list is determined by the integer codes used to represent each operator in the program. This example assumes that ADD
is zero, SUB
is one, MUL
is two, and so forth.
初始化列表中各个函数名的正确顺序取决于程序中用于表示每个操作符的整型代码。这个例子假定 ADD
是 0,SUB
是 1,MUL
是 2,接下去以此类推。
The second step is to replace the entire switch
statement with this one!
第 2 个步骤是用下面这条语句替换前面整条 switch
语句。
result = oper_func[oper](op1, op2);
oper
selects the correct pointer from the array, and the function call operator executes it.
oper
从数组中选择正确的函数指针,而函数调用操作符将执行这个函数。
An out‐of‐bounds subscript is just as illegal on a jump table as it is on any other array, but it is much more difficult to diagnose.
在转换表中,越界下标引用就像在其他任何数组中一样是不合法的。但一旦出现这种情况,把它诊断出来要困难得多。当这种错误发生时,程序有可能在三个地方终止。首先,如果下标值远远越过了数组的边界,它所标识的位置可能在分配给该程序的内存之外。有些操作系统能检测到这个错误并终止程序,但有些操作系统并不这样做。如果程序被终止,这个错误将在靠近转换表语句的地方被报告,问题相对而言较易诊断。
如果程序并未终止,非法下标所标识的值被提取,处理器跳到该位置。这个不可预测的值可能代表程序中一个有效的地址,但也可能不是这样。如果它不代表一个有效地址,程序此时也会终止,但错误所报告的地址从本质上说是一个随机数。此时,问题的调试就极为困难。
If the random address is in an area in memory that contains data, the program usually aborts very quickly due to an illegal instruction or an illegal operand address (although data values sometimes represent valid instructions, they do not often make any sense).
如果程序此时还未失败,机器将开始执行根据非法下标所获得的虚假地址的指令,此时要调试出问题根源就更为困难了。如果这个随机地址位于一块存储数据的内存中,程序通常会很快终止,这通常是由于非法指令或非法的操作数地址所致 (尽管数据值有时也能代表有效的指令,但并不总是这样)。要想知道机器为什么会到达那个地方,唯一的线索是转移表调用函数时存储于堆栈中的返回地址。如果任何随机指令在执行时修改了堆栈或堆栈指针,那么连这个线索也消失了。
更糟的是,如果这个随机地址恰好位于一个函数的内部,那么该函数就会快乐地执行,修改谁也不知道的数据,直到它运行结束。但是,函数的返回地址并不是该函数所期望的保存于堆栈上的地址,而是另一个随机值。这个值就成为下一个指令的执行地址,计算机将在各个随机地址间跳转,执行位于那里的指令。
问题在于指令破坏了机器如何到达错误最后发生地点的线索。没有了这方面的信息,要查明问题的根源简直难如登天。如果你怀疑转移表有问题,可以在那个函数调用之前和之后各打印一条信息。如果被调用函数不再返回,用这种方法就可以看得很清楚。但困难在于人们很难认识到程序某个部分的失败可以是位于程序中相隔甚远的且不相关部分的一个转移表错误所引起的。
It is much easier to make sure that the subscript used in a jump table is within range in the first place.
一开始,保证转移表所使用的下标位于合法的范围是很容易做到的。
References
[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/
[2] Pointers on C (C 和指针), https://www.cs.rit.edu/~kar/pointers.on.c/index.html
[3] 22.5 Function Pointers, https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Function-Pointers.html
相关文章:
C 语言函数指针 (Pointers to Functions, Function Pointers)
C 语言函数指针 {Pointers to Functions, Function Pointers} 1. Pointers to Functions (函数指针)2. Function Pointers (函数指针)2.1. Declaring Function Pointers2.2. Assigning Function Pointers2.3. Calling Function Pointers 3. Jump Tables (转移表)References 1. …...
Mesa llvmpipe和softpipe对比
Mesa 后端性能分析:LLVM vs Software Pipe 当调试没有显卡的时候,可以使用cpu软件模拟的mesa-3d,后端采用kms_swrast_dri.so,发现管线使用llvmpipe的速度明显优于softpipe; 背景介绍 Mesa 是一个开源的图形库…...
【Spiffo】排障:VsCode报错“过程试图写入的管道不存在”(网络环境正常且地址正常的情况下依然出现)
摘要: VsCode使用remote-ssh报错nstall terminal quit with output: 过程试图写入的管道不存在,且输出类似下图的信息 一般来说这种情况更可能是网络环境出了问题,那连不上自不必多说,这里想讨论一种特殊情况。 有一种可能性&…...
Python图形界面(GUI)Tkinter笔记(二十一):Messagebox信息提示功能控件
messagebox 就像是 tkinter 库里的一个好帮手,它能帮你弹出各种各样的消息框给用户看。这些消息框可以告诉用户很多东西,比如提示、警告或者错误信息之类的。在 tkinter 库里,messagebox 这个模块有很多不同的函数,每个函数都能弹出一种特定的消息框。用这些函数,开发者可…...
KUKA机器人如何修改程序并下载到机器人控制器中?
KUKA机器人如何修改程序并下载到机器人控制器中? 如下图所示,首先将使用的网卡的IP地址设置为自动获得, 打开workvisual软件,点击搜索,正常情况下可以搜索到项目文件,选中后双击进入, 如下图所示,此时,workvisual会自动从机器人控制器中下载项目文件到电脑上,耐心等待…...
jmeter 中 BeanShell 预处理程序、JSR223后置处理程序使用示例
1. 各个组件如何新建的? 2. "http请求" 组件内容样例: "消息体数据" 源码: {"task_tag": "face_detect","image_type": "base64","extra_args": [{"model"…...
「Mac畅玩鸿蒙与硬件53」UI互动应用篇30 - 打卡提醒小应用
本篇教程将实现一个打卡提醒小应用,通过用户输入时间进行提醒设置,并展示实时提醒状态,实现提醒设置和取消等功能。 关键词 打卡提醒状态管理定时任务输入校验UI交互 一、功能说明 打卡提醒小应用包含以下功能: 提醒时间输入与…...
前端开发【插件】moment 基本使用详解【日期】
moment.js 是一个非常流行的 JavaScript 库,用于处理和操作日期与时间。它提供了丰富的 API 来处理各种日期、时间和格式化的操作。尽管随着 Date API 的增强,moment.js 被视为“过时”,并且推荐使用 date-fns 或 luxon 等库来替代࿰…...
Apache Celeborn 在B站的生产实践
背景介绍 Shuffle 演进 随着B站业务的飞速发展,数据规模呈指数级增长,计算集群也逐步从单机房扩展到多机房部署模式。多个业务线依托大数据平台驱动核心业务,大数据系统的高效性与稳定性成为公司业务发展的重要基石。如图1,目前在大数据基础架构下,我们主要采用 Spark、Fl…...
imageio 图片转mp4 保存mp4
目录 安装: imageio 图片转mp4 numpy 保存mp4 安装: FFMPEG: pip install imageio[ffmpeg] pyav: pip install imageio[pyav] imageio 图片转mp4 import glob import osimport cv2 import imageio from natsort import natsortedfrom PIL import …...
【C语言程序设计——选择结构程序设计】求阶跃函数的值(头歌实践教学平台习题)【合集】
目录😋 任务描述 相关知识 1. 选择结构基本概念 2. 主要语句类型(if、if-else、switch) 3. 跃迁函数中变量的取值范围 4. 计算阶跃函数的值 编程要求 测试说明 通关代码 测试结果 任务描述 本关任务:输入x的值&#x…...
基于 Solana Playground (pg模式)发行自定义参数的代币
文章目录 要做的事1、水龙头(devnet 环境)2、Solana Playground2.1、选择环境 3、基于 Solana Playground (pg模式)发行自定义参数的代币3.1、账户体系3.2、代码 4、浏览器& Phantom钱包 展示代币图片4.1、 浏览器和钱包展示的…...
代码随想录算法训练营第七十天 | 拓扑排序精讲,Dijkstra(朴素版)精讲,Dijkstra(堆优化版)精讲
拓扑排序精讲 题目讲解:代码随想录 重点: 给出一个有向图,把这个有向图转成线性的排序就叫拓扑排序。拓扑排序也是图论中判断有向无环图的常用方法。拓扑排序的过程,其实就两步: 找到入度为0的节点,加入结…...
基于 Python Django 的西西家居全屋定制系统(源码+部署+文档)
博主介绍:✌程序员徐师兄、7年大厂程序员经历。全网粉丝12w、csdn博客专家、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ 🍅文末获取源码联系🍅 👇🏻 精彩专栏推荐订阅👇…...
excel填充十六进制
excel填充十六进制 A10x000020x000130x000240x000350x000460x000570x000680x000790x0008100x0009110x000A120x000B130x000C140x000D150x000E160x000F 在A1表格中,输入:“0x”&DEC2HEX(ROW()-1,4) 然后进行下拉即可生成如表格显示十六进制...
scrapy 教程
Scrapy Tutorial In this tutorial, we’ll assume that Scrapy is already installed on your system. If that’s not the case, see Installation guide. We are going to scrape quotes.toscrape.com, a website that lists quotes from famous authors. This tutorial …...
IDE和IDEA详解和具体差异
1. IDE(集成开发环境)概述 1.1 什么是 IDE? IDE(Integrated Development Environment,集成开发环境)是一种为开发者提供全面编程工具的软件应用程序。它将代码编辑、编译、调试、版本控制等功能集成在一个统一的界面中,旨在提高开发效率,减少开发者在不同工具之间切换…...
使用MPTCP+BBR进行数据传输,让网络又快又稳
1.前言 在前文《链路聚合技术——多路径传输Multipath TCP(MPTCP)快速实践》中我们使用mptcpize run命令实现了两个节点间通信使用MPTCP协议进行传输,并实现了传输速率的聚合。 实际应用中更推荐原生支持mptcp的应用,在MPTCP官网中可以看到如TCPDump、…...
【网络】网络基础知识(协议、mac、ip、套接字)
文章目录 1. 计算机网络的背景2. 认识网络协议2.1 协议分层2.2 OS与网络的关系 3. 网络传输基本流程3.1 局域网通信流程3.2 跨网络通信流程 4. Socket 编程预备4.1 理解源IP地址和目的IP地址4.2 端口号与Socket4.3传输层的典型代表4.4 网络字节序 5. socket 编程接口5.1 介绍5.…...
Unity【Colliders碰撞器】和【Rigibody刚体】的应用——小球反弹效果
目录 Collider 2D 定义: 类型: Rigidbody 2D 定义: 属性和行为: 运动控制: 碰撞检测: 结合使用 实用检测 延伸拓展 1、在Unity中优化Collider 2D和Rigidbody 2D的性能 2、Unity中Collider 2D…...
游戏引擎学习第75天
仓库:https://gitee.com/mrxiao_com/2d_game_2 Blackboard: 处理楼梯通行 为了实现楼梯的平滑过渡和角色的移动控制,需要对楼梯区域的碰撞与玩家的运动方式进行优化。具体的处理方式和遇到的问题如下: 楼梯区域的过渡: 在三维空间中&#x…...
ModelScope ms-swift:轻量级模型微调框架
ModelScope ms-swift:轻量级模型微调框架 介绍支持的模型支持的技术使用方法为什么选择ms-swift?结论 介绍 ModelScope ms-swift是ModelScope社区提供的一个官方框架,用于大型语言模型(LLMs)和多模态大型模型…...
管理加密SQLite数据库的软件工具研究
使用软件工具管理加密的 SQLite 数据库是一个常见需求,尤其是当需要保护敏感数据时。以下是实现此目标的步骤和相关工具推荐: 1. 选择支持加密的 SQLite 版本 SQLite 默认并不支持加密功能。你需要使用以下方法之一来启用加密: SQLite Encry…...
react 封装一个类函数使用方法
1.编写ProductCount函数 class ProductCount {public static getProductCount(count: number): string {if (count < 10) {return 当前数量: 0${count};}return 当前数量: ${count};} }export default ProductCount;2.在代码文件中导入 ProductCount 类。 import ProductC…...
Windows 11 上通过 WSL (Windows Subsystem for Linux) 安装 MySQL 8
在 Windows 11 上通过 WSL (Windows Subsystem for Linux) 安装 MySQL 8 的步骤如下: ✅ 1. 检查 WSL 的安装 首先确保已经安装并启用了 WSL 2。 🔧 检查 WSL 版本 打开 PowerShell,执行以下命令: wsl --list --verbose确保 W…...
解决 IntelliJ IDEA 中 Tomcat 日志乱码问题的详细指南
目录 前言1. 分析问题原因2. 解决方案 2.1 修改 IntelliJ IDEA 的 JVM 选项2.2 配置 Tomcat 实例的 VM 选项 2.2.1 设置 Tomcat 的 VM 选项2.2.2 添加环境变量 3. 进一步优化 3.1 修改 Tomcat 的 logging.properties3.2 修改操作系统默认编码 3.2.1 Windows 系统3.2.2 Linux …...
jenkins入门4 --window执行execute shell
1、启动关闭jenkins 在Windows环境下,如果你需要关闭Jenkins服务,可以通过以下几种方式: 1、使用Windows服务管理器: 打开“运行”对话框(Win R),输入services.msc,然后回车。 在服…...
51c嵌入式~单片机~合集4
我自己的原文哦~ https://blog.51cto.com/whaosoft/12868932 一、时钟失效之后,STM32还能运行? 问题: 该问题由某客户提出,发生在 STM32F103VDT6 器件上。据其工程师讲述:在其产品的设计中,STM32 的 H…...
OKHttp调用第三方接口,响应转string报错okhttp3.internal.http.RealResponseBody@4a3d0218
原因分析 通过OkHttp请求网络,结果请求下来的数据一直无法解析并且报错,因解析时String res response.body().toString() 将toString改为string即可!...
杰发科技——使用ATCLinkTool解除读保护
0. 原因 在jlink供电电压不稳定的情况下,概率性出现读保护问题,量产时候可以通过离线烧录工具避免。代码中开了读保护,但是没有通过can/uart/lin/gpio控制等方式进行关闭,导致无法关闭读保护。杰发所有芯片都可以用本方式解除读保…...
SQL 幂运算 — POW() and POWER()函数用法详解
POW() and POWER()函数用法详解 POW() 和 POWER() —计算幂运算(即一个数的指定次方)的函数。 这两个函数是等价的,功能完全相同,只是名字不同。 POW(base, exponent); POWER(base, exponent); base:底数。exponen…...
【Shell脚本】Docker构建Java项目,并自动停止原镜像容器,发布新版本
本文简述 经常使用docker部署SpringBoot 项目,因为自己的服务器小且项目简单,因此没有使用自动化部署。每次将jar包传到服务器后,需要手动构建,然后停止原有容器,并使用新的镜像启动,介于AI时代越来越懒的…...
【ArcGIS Pro二次开发实例教程】(2):BSM字段赋值
一、简介 一般的数据库要素或表格都有一个BSM字段,用来标识唯一值。 此工具要实现的功能是:按一定的规律(前缀中间的填充数字OBJECT码)来给BSM赋值。 主要技术要点包括: 1、ProWindow的创建,Label,Comb…...
VSCode函数调用关系图插件开发(d3-graphviz)
文章目录 1、如何在VSCode插件webview中用d3-graphviz绘图2、VSCode插件使用离线d3.min.js、d3-graphviz3、使用 `@hpcc-js/wasm` 包在 Node.js 环境直接转换dot为svg1、如何在VSCode插件webview中用d3-graphviz绘图 我来帮你创建一个 VS Code 插件示例,实现右键菜单触发 Web…...
OCR图片中文字识别(Tess4j)
文章目录 Tess4J下载 tessdataJava 使用Tess4j 的 demo Tess4J Tess4J 是 Tesseract OCR 引擎的 Java 封装库,它让 Java 项目更轻松地实现 OCR(光学字符识别)功能。 下载 tessdata 下载地址:https://github.com/tesseract-ocr/…...
leetcode 面试经典 150 题:同构字符串
链接同构字符串题序号205题型字符串解法哈希表难度简单熟练度✅✅✅✅ 题目 给定两个字符串 s 和 t ,判断它们是否是同构的。 如果 s 中的字符可以按某种映射关系替换得到 t ,那么这两个字符串是同构的。 每个出现的字符都应当映射到另一个字符&#…...
算法-泰波那契
力扣题目链接:1137. 第 N 个泰波那契数 - 力扣(LeetCode) 泰波那契序列 Tn 定义如下: T0 0, T1 1, T2 1, 且在 n > 0 的条件下 Tn3 Tn Tn1 Tn2 给你整数 n,请返回第 n 个泰波那契数 Tn 的值。 示例 1&…...
Mac修改文件权限
查看文件权限 ll -all 修改读写权限 sudo chmod -R arwx /usr/local/mysql-5.7.30-macos10.14-x86_64/data/a_test 修改用户分组 sudo chown -R _mysql:wheel /usr/local/mysql-5.7.30-macos10.14-x86_64/data/b_test...
如何安装和配置PHP开发环境?
要安装和配置PHP开发环境,可以按照以下步骤进行: 一、下载和安装PHP 1:下载PHP: 访问PHP官方网站(PHP: Downloads),选择适合您操作系统的版本进行下载。 2:解压并安装PHP&#x…...
深入探讨 Android 中的 AlarmManager:定时任务调度及优化实践
引言 在 Android 开发中,AlarmManager 是一个非常重要的系统服务,用于设置定时任务或者周期性任务。无论是设置一个闹钟,还是定时进行数据同步,AlarmManager 都是不可或缺的工具之一。然而,随着 Android 系统的不断演…...
【Vim Masterclass 笔记07】S05L19:Vim 剪切、复制、粘贴操作同步练习
文章目录 S05L19 Vim 剪切、复制、粘贴操作同步练习(Exercise 05 - Cut, Copy and Paste)1 训练目标2 操作指令2.1 打开 dyp.txt 文件2.2 交换文件的头两行2.3 将文件首行 put 到文件其他为止2.4 练习在光标位置的上方粘贴文本行2.5 通过交换字符顺序更正…...
【前端下拉框】获取国家国旗
一、先看效果 二、代码实现(含国旗) <!DOCTYPE html> <html lang"zh"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><…...
Elasticsearch 操作文档对数据的增删改查操作 索引库文档 操作数据 CRUD
介绍 在 Elasticsearch 中,文档的增、删、改、查操作是核心的基本功能。Elasticsearch 使用 RESTful API 提供这些操作,通常通过 HTTP 请求与 Elasticsearch 集群进行交互。 索引库 {"mappings": {"properties": {"title&qu…...
【动手学电机驱动】STM32-MBD(2)将 Simulink 模型部署到 STM32G431 开发板
STM32-MBD(1)安装 STM32 硬件支持包 STM32-MBD(2)Simulink 模型部署入门 STM32-MBD(3)Simulink 状态机模型部署 【动手学电机驱动】STM32-MBD(2)Simulink 模型部署入门 1. 软硬件条件…...
小试牛刀-SpringBoot集成SOL链
目录 一、什么是solanaj? 二、Pom依赖 三、主要类 3.1 RpcClient 3.2 PublicKey 3.3 Transaction 3.4 TransactionInstruction 四、示例代码 Welcome to Code Blocks blog 本篇文章主要介绍了 [小试牛刀-SpringBoot集成SOL链] ❤博主广交技术好友,喜欢文章的…...
数据结构大作业——家谱管理系统(超详细!完整代码!)
目录 设计思路: 一、项目背景 二、功能分析 查询功能流程图: 管理功能流程图: 三、设计 四、实现 代码实现: 头文件 结构体 函数声明及定义 创建家谱树头结点 绘制家谱树(打印) 建立右兄弟…...
【计算机网络】课程 实验二 交换机基本配置和VLAN 间路由实现
实验二 交换机基本配置和VLAN 间路由实现 一、实验目的 1.了解交换机的管理方式。 2.掌握通过Console接口对交换机进行配置的方法。 3.掌握交换机命令行各种模式的区别,能够使用各种帮助信息以及命令进行基本的配置。 4&…...
最新MySQL面试题(2025超详细版)
2025最新超详细MySQL面试题 文章目录 2025最新超详细MySQL面试题[toc]一、 SQL 和基本操作1. SQL的执行顺序2. 如何优化MySQL查询3. 常用的聚合函数4. 数据库事务5. 事务的四大特性(ACID)6. 视图7. MySQL中使用LIMIT子句进行分页8. MySQL中使用变量和用户定义的函数9. MySQL中的…...
Unity-Mirror网络框架-从入门到精通之AdditiveScenes 示例
文章目录 前言Additive Levels和Additive ScenesAdditive Levels场景介绍Portal传送门FadeInOut特效 Additive Scenes示例介绍ZoneHandlerSceneMassage 最后 前言 在现代游戏开发中,网络功能日益成为提升游戏体验的关键组成部分。Mirror是一个用于Unity的开源网络框…...
java 转义 反斜杠 Unexpected internal error near index 1
代码: String str"a\\c"; //出现异常,Unexpected internal error near index 1 //System.out.println(str.replaceAll("\\", "c"));//以下三种都正确 System.out.println(str.replace(\\, c)); System.out.println(str.r…...